Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have JTable staying on the edited cell

If someone edit the cell content of a JTable and press enter, the content is modified and the table selection moves to the next row.

Is that possible to forbid the JTable to go to the next row after a cell edition?

The reason is that my program synchronize some other widgets on cell selection using a ListSelectionListener, and I do not want to have the next row selected after editing the current cell.

like image 217
Martin Avatar asked Nov 01 '11 18:11

Martin


2 Answers

The default binding for Enter is the Action named selectNextRowCell. To override the entry in the WHEN_ANCESTOR_OF_FOCUSED_COMPONENT input map, you'll need to supply a doNothing() Action, as suggested in How to Use Key Bindings: How to Make and Remove Key Bindings.

like image 175
trashgod Avatar answered Sep 21 '22 05:09

trashgod


I'm not sure how exactly to do this, but I would look into ActionMap. You should be able to either modify or replace the Action that is mapped to the 'Enter' key.

Good luck!

like image 42
BenCole Avatar answered Sep 23 '22 05:09

BenCole