Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to return to first cell in the column after editing the last cell in column in java?
    primarykey
    data
    text
    <p>I have created a table which have 5 columns. all cells in the column 2 and 3 are editable. column 2 has a default JTextField editor and should take the number(0,1,2,3,...,9) value only. when application is loaded for the first time, automatically first cell in the column 2 become selected and the table get focus as below.</p> <pre><code>public void initFocus(){ SwingUtilities.invokeLater(new Runnable() { public void run() { itemsTable.changeSelection(0,2,false,false); itemsTable.requestFocusInWindow(); } }); } </code></pre> <p>What i want to achieve is as below:</p> <ol> <li>by pressing the number(0 until 9) cell be edited to the new value.</li> <li>by pressing Enter the next cell in the column be ready for edited.</li> <li>If user riches the last cell in the column and edit it and press Enter, first cell in the column be ready for editing again.</li> </ol> <p><strong>I have tried this in table but result is not OK:</strong> Does any body know how to catch these goals? an example of a simple table will be appreciated. thanks in advance</p> <pre><code>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 &amp;&amp; row != -1) { if (editCellAt(row, column)) { Component editor = getEditorComponent(); editor.requestFocusInWindow(); ((JTextComponent)editor).selectAll(); } if(isEditing() &amp;&amp; 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); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload