I have many custom editors for a JTable and it's an understatement to say that the usability, particularly in regard to editing with the keyboard, is lacking.
The main reason for this is that my editors are always created with a similar (though often more complex) situation to this:
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
container.add(field, BorderLayout.CENTER);
field.setText((String) value);
container.add(new JButton("..."), BorderLayout.EAST);
return container;
}
I.E a panel with more than one component inside. The actual text editor is a descendant of the component being returned as the editor.
So, rendering issues aside, from what I can tell, the JTable is focusing the component that is returned by the getTableCellEditorComponent
method so when you press a key with a cell highlighted it passes focus and the key press to the panel, thinking that's the editor.
Is there anyway I can inform JTable that the "real" editor is the JTextfield?
Adding a hacky requestFocusInWindow
on the correct component is insufficient as the key press won't get passed on.