java - Edit a specific cell in JTable on enter key and show the cursor -
i have added keylistner jtable on frame. on kepressed have code
if (ke.getkeycode()==10) { int rowindex = jtable2.getselectedrow(); int colindex = jtable2.getselectedcolumn(); jtable2.editcellat(rowindex, colindex); ke.consume();
this edit cell cursor not shown till click on mouse
do not use keylistener!
swing designed use key bindings (see swing tutorial on how use key bindings). bind action keystroke.
by default:
- the
enter
key move cell selection next row - the
f2
key place cell in edit mode
so want replace default action of enter key action of f2 key. done using key bindings:
inputmap im = table.getinputmap(jtable.when_ancestor_of_focused_component); keystroke enter = keystroke.getkeystroke(keyevent.vk_enter, 0); keystroke f2 = keystroke.getkeystroke(keyevent.vk_f2, 0); im.put(enter, im.get(f2));
also, check out key bindings list of default bindings swing components.
Comments
Post a Comment