Sunday, 15 March 2015

java - focus next cellEditor and sellect all text in it in JTable when press enter key -



java - focus next cellEditor and sellect all text in it in JTable when press enter key -

i want come in key deed tab key on jtable. know problem has been asked few time already, , used solution found in page : use come in key deed tab key on jtable.

keystroke tab = keystroke.getkeystroke(keyevent.vk_tab, 0); keystroke come in = keystroke.getkeystroke(keyevent.vk_enter, 0); inputmap im = table.getinputmap(jtable.when_ancestor_of_focused_component); im.put(enter, im.get(tab));

and solution work charm. when using tab key, i've overridden changeselection of jtable,and override gettablecelleditorcomponent of cell editor selectall text in textfield in next cell :

in jtable

@override public void changeselection(int row, int column, boolean toggle, boolean extend) { super.changeselection(row, column, toggle, extend); if (editcellat(row, column)) { component editor = geteditorcomponent(); editor.requestfocusinwindow(); } }

an in celleditor

@override public component gettablecelleditorcomponent(jtable table, object value, boolean isselected, int row, int column) { if (isselected ) { swingutilities.invokelater(new runnable() { @override public void run() { textfield.selectall(); } }); } homecoming super.gettablecelleditorcomponent( table, value, isselected, row, column); }

so when stroke tab key next cell focused , text in sellected, when type come in key first time cell loose focus, , sec come in next cell gain focus , text in selected.

so question is: there way first come in loose focus cell , gain focus next 1 (so deed tab key)

don't know if create difference i've overridden changeselection(...) method cell selection:

if (editcellat(row, column)) { component editor = geteditorcomponent(); editor.requestfocusinwindow(); ((jtextcomponent)editor).selectall(); }

post sscce demonstrates problem if doesn't help.

java swing jtable key-bindings enter

No comments:

Post a Comment