Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java swing issue from 1.4 to 1.6

 
Pravin Sutrave
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

We are migrating from java 1.4 to 1.6 with frontend being Java Swing. Now the focus is giving us a very hard time.
The main issue is when we tab out of a textfield, focuslost method is called in which we validate the content of the textfield. If the content is correct we return true and the focus moves ahead to the next textfield. If the content is invalid we show a popup validation message in JDialog, call the same textfield.requestFocus() and return false. Now on calling this textfield.requestFocus() again before returning false the focuslost is again triggered on the textfield and the validation message is displayed again in the popup. This happens only twice, everywhere we show a validation message in a popup and request the focus back on the field.
Please help us.
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your code respect Swing's single threaded rule? If not, fix that first.

See the documentation for requestFocusInWindow():
... developers are strongly encouraged to use this method over requestFocus when possible.


Additionally, you may need to wrap the request in invokeLater(...).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic