3

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?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Daniel
  • 681
  • 2
  • 11
  • 20
  • do you need to understand the entire process, from handling the button action to setting the table editable? – akf Jun 25 '09 at 04:30
  • Why don't you simply allow every row to be editable. Maybe you only want the second column editable? What makes it different to click and edit right away than using a separate edit button? – akarnokd Jun 25 '09 at 07:37
  • 1
    I only want one row to be editable to avoid people accidently changing rows they did not mean to change. By clicking a row and clicking edit, it means they absolutley mean to edit the row. Overiding isCellEditable I know how I owuld do this, thanks. – Daniel Jun 25 '09 at 21:28

1 Answers1

5

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

akf
  • 38,619
  • 8
  • 86
  • 96