I have a JTable containing JComboBox editors initialized somewhat as
JComboBox comboBox = ...; TableColumn tc = table.getColumnModel().getColumn(i); tc.setCellEditor(new DefaultCellEditor(comboBox));
This works fine, but I would like to be able to navigate in the table and update values ββonly using the keyboard. Now it is possible with the help of combo boxes, but if I want to update the value "1", I must first press the key to activate the combo box, and then press "1" to select the item.
So, I want me to be able to press "1" and the item will be selected with just one keystroke.
For text cells, I managed to do this using prepareEditor, as shown below ...
@Override public Component prepareEditor(TableCellEditor editor, int row, int column) { Component c = super.prepareEditor(editor, row, column); if (c instanceof JTextComponent) { ((JTextComponent) c).selectAll(); } return c; }
... but I was not able to figure out what to do with the combo box.
One possibility could be your own TableCellEditor, but if there is a simpler solution that would be nice =)
br, Toko
Touko source share