• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

setfocus problem.

 
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();
}
}
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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.
 
Ranch Hand
Posts: 530
Hibernate Eclipse IDE Java
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!