Sunday, April 3, 2011

Only one row editable on JTable

I am trying to make a special kind of jtable. I want the entire table to by default be NOT editable. But when the user clicks a row, then clicks the "Edit" jbutton, that specific row is editable. and once they deslect the row its no longer editable.

How would I go about doing this?

From stackoverflow
  • to control which cells are editable, you will need to extend either JTable or JTableModel (see the call to the model in the example below) to ensure that this method from JTable returns true for all the cells in the row(s) you want editable based on your spec.

      public boolean isCellEditable(int row, int column) {
          return getModel().isCellEditable(row, convertColumnIndexToModel(column));
      }
    

    also take a look at this tutorial to learn about TableCellEditors

0 comments:

Post a Comment