0

Below is the snippet of my code. I have a JTable. I have extended the DefaultCellEditor to create my own editor.I have key listeners and mouse listeners added for the cells.I have a JButton as well. When i click on the JButton, i want the first cell in the JTable to enter edit mode.. For this i have used requestFocus and editCellAt(0,0). I have put this code in the actionperformed.

public void actionPerformed(ActionEvent e)
{
     System.out.println("action performed");

     if(e.getSource().equals(btn))
     {
    oTable.requestFocus();
    oTable.setRowSelectionInterval(0, 0);
    oTable.editCellAt(0, 0);
     }
}

This places the cursor in the first cell. But when i type anything, the key events are not fired! Note: if i use my mouse to click on the cell and then type, it does fire key events. But I don't want to do this extra click.

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

6

Seems to work for me. Maybe you can try the following:

table.editCellAt(0, 0);
table.getEditorComponent().requestFocus();
Guillaume Polet
  • 47,259
  • 4
  • 83
  • 117
  • This not only solves this question, but also "How to grammatically edit a cell or make a cell of a selected row available for editing?". Solved my issue, too :) – instinct May 28 '15 at 05:45