This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Focus issues among JTextField and Dialogs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus issues among JTextField and Dialogs" Watch "Focus issues among JTextField and Dialogs" New topic
Author

Focus issues among JTextField and Dialogs

David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, there:

After upgrading jdk from 1.3 to 1.4, we met following focus issues:
Ex. We have 2 text fields, textTest1 and textTest3, and one dialog. textTest1 registered to a key listener so that when 'Esc' key pressed, the dialog popped up, after pressed 'ok' key in that dialog, we want to transfer focus to another text field textTest3 (textTest3.requestFocus() is called inside keyPressed() method). After I added a focusListener for textTest3, I noticed the difference between jdk1.3 and 1.4:
jdk1.3: only focusGained() is called once.
jdk1.4: a. focusGained() is called (gained focus from "OK" button of dialog); b. focusLost() is called( focus lost to textTest1); c. focusGained() is called again (gained focus from textTest1).
My problem is that those extra focusGained() and focusLost() called in jdk1.4 brings me some issues in my application. Is there any straightforward way to ignore these 2 extra function calling? I can find 2 options:
a. added focus listener for textTest1, and remove textTest3.requestFocus() from keyListener to that focusListener, however it doesn't work for my application (too many components should add that focusListener);
b. added a flag, and set that flag before textTest3.requestFocus is called, and ignore those 2 extra callings.
So, again is there any other option besides above 2 can solve my issue? I included an example code below:


Highly appreciated if any comments, suggestions on that issue, thanks a lot in advance.
David
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Focus issues among JTextField and Dialogs
 
Similar Threads
Pressing Tab key in IE with latest JRE version
Issues when popup a dialog from keyReleased event
JComboBox and FocusListener
requestFocus() is not working across applications
KeyListener working randomly