• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setfocus problem.

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic