Traversing Focus Using Enter Key
Please Try to Help Me on this ............
I Have a Screen where I need to traverse focus (it has textfields, combo boxes and buttons) when I press the Enter Key (like Tab).
I used a Key listener and was able to do it (to a certain point)
The code I have written is below ..
Now The problem is when the focus sets on a JComboBox, it wont go further (tab works). I know that the enter key in a JComboBox is used to select a item.
So what I need is first to be able to select an item using the enter key and when press enter key again, the focus must go to the next component.
Is there a way to do it ?
(JCheckBox and JButton has similar problems)
SymKey aSymKey = new SymKey();
textfield1.addKeyListener(aSymKey);
textfield2.addKeyListener(aSymKey);
combobox1.addKeyListener(aSymKey);
combobox2.addKeyListener(aSymKey);
checkbox1.addKeyListener(aSymKey);
textfield3.addKeyListener(aSymKey);
button1.addKeyListener(aSymKey);
class SymKey extends KeyAdapter {
public void keyPressed(KeyEvent e){
if (e.getKeyCode() == e.VK_ENTER) {
if (e.isShiftDown())
FocusManager.getCurrentManager().focusPreviousComponent((JComponent)e.getSource());
else
FocusManager.getCurrentManager().focusNextComponent((JComponent)e.getSource());
}
}
}

