javaswingfocusjtablefocusmanager

JTable not losing focus on ENTER and TAB


table.changeSelection(table.getRowCount()-1, 3, false, false);

after setting the cell selection like above, the cell is selected and if i enter the value in to the cell, the cell goes to editing mode. But, after the value is entered, if i press ENTER or TAB key the cell is still in editing mode. If i press some where on other component then only the cell closes editor mode.

how to solve this?


Solution

  • after setting the cell selection like above, the cell is selected and if i enter the value in to the cell, the cell goes to editing mode

    1. for better help sooner post an SSCCE demonstraded your issue about table.changeSelection and TableCellEditor

    2. have to override stopCellEditing

    depends of your TableCellEditor

    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    

    or

    @Override
    public boolean stopCellEditing() {// @see CellEditor#stopCellEditing()
        fireEditingStopped();
        return true;
    }