This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JComboBox internals  RSS feed

 
aantal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy - I've got a mean JComboBox problem.
I am making a JComboBox do line completion, and in order to do so, I have a keylistener attached to the internal JTextField from the JComboBox. Everything works fine, except for one thing - when a user is scrolling down (via keyboard) in the JComboBox popup window, and the find the entry they want, and hit Tab, the focus goes to the next field, but the popup is still showing.
I have tried everything I can think of: hiding it manually in my keylistener, hiding it manually in keylisteners attached to the other components (using getComponents() then looping through them), overriding the processKey() method...nothing works. It is like the Tab event is being eaten by something before it gets to me because I never even get a VK_TAB.
Any ideas?
 
aantal
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoops..I guess that is actually the default behavior of the JComboBox:
create a JComboBox,
Add some items,
make it editable,
run the program, and then:
- click in the editable JComboBox, type a couple of characters
- press the 'DOWN' key (making the popup window appear)
- then press the down key a few more times so that you are scrolling through the list
- then press TAB
You will move to the next field, but the popup will stay showing, and you can't get it to hide unless you go back to that field, with the mouse or keyboard.
This is a really annoying behavior - has anyone gotten around it?
muchas gracias.
-aa
 
eric moon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, here's an idea. Don't know if it will work. The function of the TAB key is defined by the FocusManager. That's why you don't see your tabs. The focus manager consumes them before they get to your component's input methods. So you could subclass DefaultFocusManager and set it as the focus manager for your frame. Override the focus manager's processKeyEvent method, so that when you get a TAB key with a combo box as the source, it doesn't go to the next component right away. Maybe you could send focus to the previous component, back to the combobox, and on to the next component. You may need to cache the selected value for the combo box, since it might get lost as the focus comes back.....
I'd be curious if it works.
HTH
e

[This message has been edited by eric moon (edited April 12, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!