This code calls a routine when enter is pressed in a JTable
(called gametable
). It works well, but I would like the same Action
to be called when moving up or down in the JTable
without the need for pressing enter; I can't get it to work. I tried substituting VK_ENTER
with VK_UP
, but I am unable to move up and down the table?
KeyStroke enter = KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER, 0);
gameTable.getJTable().unregisterKeyboardAction(enter);
gameTable.getJTable().registerKeyboardAction(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
synchronized (this) {
gotoGame(gameTable.getSelectedIndex());
}
}
}, enter, JComponent.WHEN_FOCUSED);
I can't figure it out. Can someone help me?