开发者

Editable JTables - action of first key typed in a text field

开发者 https://www.devze.com 2023-03-22 10:28 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消