This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes key event on JComboBox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "key event on JComboBox" Watch "key event on JComboBox" New topic

key event on JComboBox

venkat paruchuri

Joined: Aug 15, 2001
Posts: 28
Is it possible to handle key events on JComboBox? I need to fire an event on JCOmboBox by hitting 'Enter Key' on it. Please help me ASAP. Immediate help is appreciated..
Renee Zhang
Ranch Hand

Joined: Sep 10, 2001
Posts: 72
At first, please make yourComboBox editable.
Try this:
class CBAgent extends KeyAdapter
protected JComboBox m_comboBox;
protected JTextField m_editor;
public CBAgent(JComboBox comboBox)
m_comboBox = comboBox;
m_editor = (JTextField)comboBox.getEditor().getEditorComponent();
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER) {
Add keyEvent to your CombiBox
CBAgent agent = new CBAgent(yourCB);
I hope that can solve your problem.
Good lucks!
venkat paruchuri

Joined: Aug 15, 2001
Posts: 28
Renee Zhang,
Thank you very much for your great help. I need to implement the same functionality in two places. I could manage with a single Adapter class effectively. I could overcome the one week long problem with your help.
thanks again,
subject: key event on JComboBox
It's not a secret anymore!