tags:

views:

43

answers:

1

I have a custom editor composed of several components. Something like:

class MyCellEditor extends AbstractCellEditor implements TableCellEditor {
    JTextArea textArea;
    JButton button;
    JPanel panel;

    MyCellEditor() {
        textArea = new JTextArea();
        button = new JButton();
        panel = new JPanel(new BorderLayout());
        panel.add(textArea, BorderLayout.CENTER);
        panel.add(button, BorderLayout.EAST);
    }

    public Component getTableCellEditorComponent(JTable table, Object value,
            boolean isSelected, int row, int column) {
        textArea.setText((String) value);
        return panel;
    }

    public Object getCellEditorValue() {
        return textArea.getText();
    }
}

I want the inner textArea to grab focus when editing starts. It works just fine when I click the cell, but not when I navigate the table with keyboard and start typing in this cell.

How can I fix this?

+1  A: 

I had the same problem some time ago and took me ages to find a solution. Tried a lot with focuslistener and stuff, but nothing really seemed to work the way I wanted it to until I found this useful article by Santhosh Kumar.

Its well written and should fix your problem.

Greetz, ymene

ymene