A EVENT conflict problem....
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Xavi_Lopez
Posted On:   Wednesday, July 7, 2004 05:36 AM

Hi everyone ! I have one problem with swing, first thing the user enters a number onto a jTextField. Next what the user typed in is checked (must be in a range) whenever he presses 'ENTER' or defocuses the textField. I've treated that with a KeyListener and a FocusListener. The problem is that when the user's value is wrong, and the user presses 'ENTER' onto the textField, the message pops up (Good!). But textfield defocuses and message gets focus (Bad !! another message pops up). Well i just tried setting the value right before popping the message up in the keyListener, but the same happens... And another one, when the user clicks the 'OK' button to accept value, if value is incorrect, message pops up (textfield defocused) but button gets like "pressed"    More>>

Hi everyone ! I have one problem with swing, first thing the user enters a number onto a jTextField. Next what the user typed in is checked (must be in a range) whenever he presses 'ENTER' or defocuses the textField. I've treated that with a KeyListener and a FocusListener. The problem is that when the user's value is wrong, and the user presses 'ENTER' onto the textField, the message pops up (Good!). But textfield defocuses and message gets focus (Bad !! another message pops up). Well i just tried setting the value right before popping the message up in the keyListener, but the same happens...

And another one, when the user clicks the 'OK' button to accept value, if value is incorrect, message pops up (textfield defocused) but button gets like "pressed" when user rolls mouse over it later (until he clicks on it again).

I'd be grateful to anyone who has had seen this before and could help me. Any idea? Come on, post it ;-)!

   <<Less

Re: A EVENT conflict problem....

Posted By:   Eddie_Po  
Posted On:   Friday, July 9, 2004 03:25 AM

try using a javax.swing.text.Document in your JTextField.
this class would do the necessary checking for the inputed characters via overwriting its insertString(...) method.

cheers. :)

Re: A EVENT conflict problem....

Posted By:   niklas_gustafsson  
Posted On:   Thursday, July 8, 2004 12:17 AM

I had the same problems, but in my case i extended the

JOptionPane to set some common switches to prevent this.







It is not bad that the message got focus

this is the common way to use message-boxes.



Probably you get both a KeyAction and some FocusAction



In the FocusListener ( FocusLost ), you can

use some switch to sheck if the textField had focus
.


Print out something on the console from

the keyListener and the FocusListener so you can se

when they are fired.


About | Sitemap | Contact