• 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

ENTER KEY with JComboBox

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to move the focus when user presses ENTER key.
I have 2 comboboxes and then some textfields.
I had implemented the KeyListener interface and overridedn keyPressed method.
when i press enterkey on a combobox its not movinf to next feild.Its working fine with TextField.from one text field to another focus is movinf on press of ENTER key.
Please suggest me if i am doing some thing wrong??
Here is the implementation.
public void keyPressed(KeyEvent evt)
{
int keyCode = evt.getKeyCode();
if (evt.getSource() == m_AccountCBox)//m_AccountCBox is a JComboBox
{
if (keyCode == KeyEvent.VK_ENTER)
{
m_SecurityCBox.requestFocus();
}
}
else if (evt.getSource() == m_SecurityCBox)//m_SecurityCBox is a JComboBox
{
if (keyCode == KeyEvent.VK_ENTER)
{
m_AmountTField.requestFocus();
}
}
else if (evt.getSource() == m_AmountTField)
{
if (keyCode == KeyEvent.VK_ENTER)
{
m_PriceTField.requestFocus();
}
}
else if (evt.getSource() == m_PriceTField)
{
if (keyCode == KeyEvent.VK_ENTER)
{
m_UnitsTField.requestFocus();
}
}
else if (evt.getSource() == m_UnitsTField)
{
if (keyCode == KeyEvent.VK_ENTER)
{
m_AmountTField.requestFocus();
}
}
}
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I noticed the above behavior of JComboBox. I tried the same approach but it didn't work.
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public void keyPressed(KeyEvent ke)
{
if(ke.getKeyCode() == KeyEvent.VK_ENTER)
{
if(ke.getSource() == c1)
{
c2.requestFocus();
}
else if(ke.getSource() == c2)
{
textPane.requestFocus();
}
else if(ke.getSource() == tf1)
{
c1.requestFocus();
}
}
}
Why I don't know.. It's working for me. I have tesetd it with BorderLayout also..
 
reply
    Bookmark Topic Watch Topic
  • New Topic