swing - how to return to first cell in the column after editing the last cell in column in java? -
i have created table have 5 columns. cells in column 2 , 3 editable. column 2 has default jtextfield editor , should take number(0,1,2,3,...,9) value only. when application loaded first time, automatically first cell in column 2 become selected , table focus below.
public void initfocus(){ swingutilities.invokelater(new runnable() { public void run() { itemstable.changeselection(0,2,false,false); itemstable.requestfocusinwindow(); } }); }
what want achieve below:
- by pressing number(0 until 9) cell edited new value.
- by pressing enter next cell in column ready edited.
- if user riches last cell in column , edit , press enter, first cell in column ready editing again.
i have tried in table result not ok: body know how catch these goals? example of simple table appreciated. in advance
itemstablemodel = new defaulttablemodel(){ @override public boolean iscelleditable(int row, int column) { return column == 2 || column==3; } }; itemstablemodel.setcolumnidentifiers(new object[]{"product", "itemcode","qty","date", "productid"}); itemstable = new jtable(itemstablemodel){ public void changeselection(int row, int column, boolean toggle, boolean extend) { super.changeselection(row, column, toggle, extend); if(column==2 && row != -1) { if (editcellat(row, column)) { component editor = geteditorcomponent(); editor.requestfocusinwindow(); ((jtextcomponent)editor).selectall(); } if(isediting() && row == itemstable.getrowcount()-1) { super.changeselection(0, 2, toggle, extend); component component = itemstable.getcelleditor(0,2).gettablecelleditorcomponent(itemstable,getvalueat(row, column),true,row,column); component.requestfocusinwindow(); ((webtextfield)component).selectall(); } } } }; itemstable.setdefaultrenderer(object.class, retrieveitemstablecellrenderer()); itemstable.setcellselectionenabled(true);
Comments
Post a Comment