• 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

[URGENT]Trapping focus loosing of Editable JCombo box.

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic