Printable character as JMenuItem accelerator not properly consumed
Hi,
I am using a simple character (e.g. 'n') without a CTRL or ALT mask
as acceleator for a JMenuItem. The menu item triggers an editing
action in a JTable (eventually `editCellAt()' is called). When I
access this function through the accelerator the key is not consumed
before the editing mode is entered, i.e. the 'n' appears in the input
field.
The code looks roughly like this:
The menu item:
// Abw=E4rts weitersuchen
item = new JMenuItem("Next");
item.setMnemonic(KeyEvent.VK_N);
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
table.startEditingAt(42, 0, 0);
}
});
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, 0));
The table:
@Override
public void startEditingAt(final int row, int start, int length) {
if (row >= getRowCount()) {
return;
}
setRowSelectionInterval(row, row);
final MyTableModel model = (MyTableModel) getModel();
editCellAt(row, MyTableModel.TEXT_COLUMN, new
EventObject(model));
// ...
}
Is there any way I can use the above accelerator while avoiding this
behaviour?
Cheers,
Martin