• 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

How to drop the list of a JcomboBox?

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Swing Gurus,
I have set a label for a comboBox, and the label has it mnemonic key setup. When I use Alt+mnemonic key of the label, I want to see the focus move to the comboBox and the list box should drop. (right now the list can drop only when the mouse is pointing the comboBox)
Thansk a lot.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi xiao li

add a key listener to the container that contains this combobox and label and in the event code add the popup method of combobox
the code somewhat look like this
your_container.addKeyListener(new KeyAdapter()
{
public void keyPressed(KeyEvent ke)
{

if(ke.getKeyCode() == KeyEvent.VK_your-mnemonic-character goes here)
{
combobox.showPopup();
}

}
});
alternatively you can close the combobox with hidePopup() method.

i think this would help you,
lavanya
 
xiao li
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lavanya,
I tried your suggestions, add KeyListener to the comboBox's container, and add one more variable m_ProcessKey. and this is my added code:
/**
* Handle the key pressed event
*/
public void keyPressed(KeyEvent e)
{
if(!m_ProcessKey && e.getKeyCode()==18)//ALT=18
{
m_ProcessKey = true;
}
}
/**
* Handle the key released event
*/
public void keyReleased(KeyEvent e)
{
if(m_ProcessKey && e.getKeyCode()==18)//ALT=18
{
m_ProcessKey = false;
}
}

/**
* Handle the key typed event
*/
public void keyTyped(KeyEvent e)
{
if(m_ProcessKey)
{
if(e.getKeyChar()=='m') // my mnemonic key is M
{
m_Combo.showPopup();
}
else
{
m_Combo.hidePopup();
}
}
}
It works! Thanks a lot.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic