Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[URGENT]Trapping focus loosing of Editable JCombo box.

 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic