• 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

key event on JComboBox

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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..
thanks
venkat
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
m_editor.addKeyListener(this);
}
public void keyPressed(KeyEvent e) {
if (e.getKeyCode()==KeyEvent.VK_ENTER) {
System.out.println("Howdy!");
}
}
}
Add keyEvent to your CombiBox
CBAgent agent = new CBAgent(yourCB);
I hope that can solve your problem.
Good lucks!
 
venkat paruchuri
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
venkat
 
reply
    Bookmark Topic Watch Topic
  • New Topic