tags:

views:

40

answers:

2

JTable cells by default are in append mode when the cell is double clicked on. Is there a way to make the cell default to overwrite mode instead, IOW, select the contents of the cell so that if the user started typing the old text would be replaced by the new text without having to manually erase it?

+3  A: 

You should be able to do this by creating your own TableCellEditor, which can be assigned to the parent table using setCellEditor(). This object is a factory that is called by the JTable whenever the user starts editing a cell, to create the field used to do the actual editing. You can return your own JTextField, and simply avoid setting the old value to achieve what your asking. You'll also have to attach a listener to the text field to update the value in the table when the user has finished typing.

Emil H
Using this approach you may need to create a custom editor for every type of data. One for String, Integer etc.
camickr
A: 

You might find the Table Select All Editor helpful.

camickr