Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setfocus problem.

 
Nagendra Shastry
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a text box and a button. Once the text box looses focus, focus has to be set to button. I have written the following code. But it isn't working. What is the problem?
txtMod1.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {

orderCreationAction.setOrderValueReturned(Integer.valueOf(0));
cleanModelData(false);
btnModelSearch.setFocus();
}
}
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When posting code, please UseCodeTags <-link. What's a 'text box'? Is this Swing or AWT code? Also check out ItDoesntWorkIsUseless <-link.

To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem. Note that this should have the minimum code needed to reproduce the problem scenario, and no dependencies on non-JDK classes.
 
Nam Ha Minh
Ranch Hand
Posts: 502
Eclipse IDE Firefox Browser Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagendra Shastry wrote:
I have a text box and a button. Once the text box looses focus, focus has to be set to button. I have written the following code. But it isn't working. What is the problem?
txtMod1.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent evt) {

orderCreationAction.setOrderValueReturned(Integer.valueOf(0));
cleanModelData(false);
btnModelSearch.setFocus();
}
}


Try to place the setFocus() call in a SwingUtilities.invokeLater() call.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic