Nessaj Nguyen
Nessaj Nguyen

Reputation: 173

SWING JTable, cell start to edit event

I have a JTable and these cells of it are editable, there are any ways to handle the "cell start to edit" event in order that I can display a message when users start to edit a cell.

Upvotes: 6

Views: 3385

Answers (2)

camickr
camickr

Reputation: 324118

Add a PropertyChangeListener to the JTable:

//
//  Implement the PropertyChangeListener interface
//
    @Override
    public void propertyChange(PropertyChangeEvent e)
    {
        //  A cell has started/stopped editing

        if ("tableCellEditor".equals(e.getPropertyName()))
        {
            if (table.isEditing())
                // code for editing started;
            else
                // code for editing stopped;
        }
    }

Upvotes: 6

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285403

If this were my code, I'd start by trying to override the TableEditor's getTableCellEditorComponent method. Inside of the override, I'd call the method that I want to call when editing starts, and then I'd call the super's getTableCellEditorComponent method inside the override.

You can find out more details on how to use custom cell editors (since this is what you need to do) at the JTable tutorial.

Upvotes: 8

Related Questions