JTable - Getting a cell into Edit mode on pressing Tab

后端 未结 3 1211
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 08:40

This is possibly has a trivial solution, but I am at the end of my tether so I hope somebody can help out.

I use a JTable which has a custom renderer and a custom ed

3条回答
  •  醉话见心
    2020-12-30 09:38

    Thank you n00213f. The thread and example from your post were helpful. By overloading the changeSelection method in JTable as hinted to in the thread, JTable checks if a cell is editable every time the selection is changed. If the cell is editable, it will show the CellEditor and transfer focus to the editor component.

    For completeness, here is my solution:

      JTable myTable = new javax.swing.JTable()
      {
                public void changeSelection(final int row, final int column, boolean toggle, boolean extend)
                {
                    super.changeSelection(row, column, toggle, extend);
                    myTable.editCellAt(row, column);
                    myTable.transferFocus();
                }
      };
    

提交回复
热议问题