File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes setfocus problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "setfocus problem." Watch "setfocus problem." New topic
Author

setfocus problem.

Nagendra Shastry
Greenhorn

Joined: Oct 26, 2010
Posts: 19

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

Joined: May 03, 2008
Posts: 4638
    
    5

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.

luck, db
There are no new questions, but there may be new answers.
Nam Ha Minh
Ranch Hand

Joined: Oct 31, 2011
Posts: 498

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.


PM Me If You Want to get Urgent Help on Java Programming
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setfocus problem.