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 [URGENT]Trapping focus loosing of Editable JCombo box. 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 "[URGENT]Trapping focus loosing of Editable JCombo box." Watch "[URGENT]Trapping focus loosing of Editable JCombo box." New topic
Author

[URGENT]Trapping focus loosing of Editable JCombo box.

Anirban dutta
Ranch Hand

Joined: Aug 08, 2002
Posts: 89
Dear all,
I have a editable combo box on a JPanel contained in a JFrame. Now I want to do some action whenever the user types something in the textfield area of the editable combo box and then presses tab or shifts the focus from combo box to somewhere else by any means. But I am not able ot trap the focus event for the same by any ways. Please help me out in this regard. It's urgent.
Thanks to everybody in advance
Abhik Sarkar
Ranch Hand

Joined: Jun 14, 2003
Posts: 61
I think using an ActionListener instead of a FocusListener on the comboBox will do what you want...
Good Luck!
Abhik.
Originally posted by Anirban dutta:
Dear all,
I have a editable combo box on a JPanel contained in a JFrame. Now I want to do some action whenever the user types something in the textfield area of the editable combo box and then presses tab or shifts the focus from combo box to somewhere else by any means. But I am not able ot trap the focus event for the same by any ways. Please help me out in this regard. It's urgent.
Thanks to everybody in advance
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Actually, because of the nature of how the tab key works, you have to disable the default event for tab before you can trap the tab event with a FocusListener. So you should use this method:
combo.setFocusTraversalKeysEnabled(false);
Just remember that in your FocusEvent method where you do your work, if you want it to then tab to the next component, you have to code that manually by requesting focus on the next component (since you disabled the tab ability).
The other option is what was already suggestion, I will just elaborage a bit. If you want to use the ENTER key instead of tab, you would want to use an ActionListener with an ActionEvent and pressing ENTER will trigger this action. Again, if you want focus to change to the next component after ENTER is pressed, you will need to code that move manually, or you will have to hit enter and then hit tab to move.
Hope that helps.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [URGENT]Trapping focus loosing of Editable JCombo box.