javaswingjtabletablecellrenderer

Java JTable enabled but not editable with a TableCellRenderer and a defaultTableModel


I'm using TableCellRenderer to render a button in a cell for a JTable created with Matisse in netbeans.

My problem is ... When a double click on the button, I can reach the text field behind. So I want to set the textfield not editable.

For now, my setEnabled are on true: table_watchlistMain.setEnabled(true); I need that because I want to user to be eable to select a row ...

I'm using a DefaultTableModel... do I need to make my own model?

I'm just searching a solution to put the jtable enabled, but not editable. this is possible??


Solution

  • The DefaultTableModel.isCellEditable() method always returns true:

    Returns true regardless of parameter values.

    So, yes, you should create your own model, for example:

    public class MyTableModel extends DefaultTableModel
    {
        @Override
        public boolean isCellEditable(int row, int column)
        {
            return false;
        }
    }