Get correct editing behaviour in JTable using java DefaultCellEditor
You can go into a cell in a Jtable either by clicking on it, or by going into it using cursor keys/tabs. With defaultCellEditor and a JtextField if you go in using cursor keys the caret is pu开发者_高级运维t at the end of the existing text field, whereas if you double click the field it will highlight the last word.
Whereas spreadsheets seem to work (such as Open Office Calc) the same way for a double clcking, but if you tab into 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 app to work the same way as the spreadsheet. By subclassing DefaultCellEditor and adding
final Caret caret = editField.getCaret();
caret.setDot(0);
editField.setText("");
I can get it to work how I want when tabbing but it also clears the field on double click which I dont want.
So please how can I determine if cell editing has been triggered by keyboard or mouse ?
override the isCellEditable(EventObject anEvent) method too.
So that you can capture the event which is going to trigger (or not) the table edition and act the way you want
精彩评论