If an editable cell is selected in a JTable (selected by using the arrows keys) then the next keystroke you make will append the key you type to the text in that field.
EG: demo from the Java Turorials
http://download.oracle.com/javase/tutorialJWS/uiswing/components/ex6/TableDialogEditDemo.jnlp
Use arrows to goto the cell containing the word "Snowboarding" then type the letter "s". The cell now 开发者_运维百科contains "Snowboardings".
I would prefer that the first character you type replaces the text in the field, so in this example it would now contain just "s". This would be more in line with Excel.
Does anyone have any ideas how to do this?
See
public boolean shouldSelectCell(EventObject anEvent)
of DefaultCellEditor Or you can use
public Component prepareEditor(TableCellEditor editor, int row, int column)
call super and cast the editor to JTextField. Then call selectAll() of the JTextField
精彩评论