1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| InputMap im = _table.getInputMap(JXTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
// Have the enter key work the same as the tab key
KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
final Action oldEnterAction = _table.getActionMap().get(im.get(enter));
Action stopEditAction = new AbstractAction()
{
public void actionPerformed(ActionEvent e) {
oldEnterAction.actionPerformed( e );
int row = _table.getSelectedRow();
int col = _table.getSelectedColumn();
TableCellEditor editor = _table.getCellEditor(row, col);
if (editor != null)
editor.stopCellEditing();
}
};
_table.getActionMap().put(im.get(enter), stopEditAction); |
Partager