How do i add a customized CellEditorListener to my JTable?

I start typing my code:

private void addMyCellEditorListener() {

    class MyCellEditorListener implements CellEditorListener
    {
        public MyCellEditorListener() {}

        public void editingCanceled(ChangeEvent e) {}

        public void editingStopped(ChangeEvent e) {
            if(row == 0 && column > 0)
                rechargeTableWithFindedResults(graphicTable.getValueAt(row,column));
            else
                dataTable.setValueAt(graphicTable.getValueAt(row,column),row,column);
        }
    };

    .... addCellEditorListener(new MyCellEditorListener());
}

I would like my graphicTable to detect data changes into its cells by giving it a customized CellEditorListener, but I really can't understand how to add it. I tried several times with a code like the following:

DefaultCellEditor editor = new DefaultCellEditor(new JTextLabel());
editor.addCellEditorListener(new MyCellEditorListener());
this.graphicTable.setCellEditor(editor);

... or:

this.graphicTable.setCellEditor(this.graphicTable.getCellEditor().addCellEditorListener(new MyCellEditorListener()));

... however these techniques give me a NullPointerException in both cases.

I have looked around through forums to get a solution, but they are just getting me more confused.

Every hint would be appreciated.

Thanks in advance.

Answers


Your approach is incorrect. You can easily detect data changes in your TableModel, specifically in setValueAt method. Once you detected the change and reacted on it, you have to call one of the fireTable.. methods to let table and all other listeners know that data changed

There no need to assign any listeners to cell editors at all.


Need Your Help

source code for LINQ 101 samples

linq

where can I find the code for GetCustomerList(), GetOrderList() for the LINQ 101 samples

SQL query to find record with ID not in another table

sql database

I have two tables with binding primary key in database and I desire to find a disjoint set between them. For example,

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.