Get the correct editing behavior in JTable using java DefaultCellEditor

You can enter a cell in Jtable either by clicking on it or by going to it using the cursor keys / tabs. With defaultCellEditor and JtextField, if you use the cursor keys, the carriage is placed at the end of the existing text field, whereas if you double-click on the field, it will highlight the last word.

While spreadsheets seem to work (e.g. Open Office Calc) the same way for double clcking, but if you enter the field and start editing, the field is cleared, and the first character pressed becomes the first value in the field and so on.

I want my application to work just like a spreadsheet. Subclassing DefaultCellEditor and adding

final Caret caret = editField.getCaret();
    caret.setDot(0);
    editField.setText("");

I can make it work the way I want it when tabbing, but it also clears the double-click box that I don't need.

So, please, how can I determine if editing a cell is caused by a keyboard or mouse?

+2
source share
1 answer

override the isCellEditable (EventObject anEvent) method.

So that you can capture an event that will fire (or not) the version of the table and act the way you want

+2
source

Source: https://habr.com/ru/post/1770704/


All Articles