posted 20 years ago
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();
}
}
}