Only one row editable on JTable

你说的曾经没有我的故事 提交于 2019-12-23 17:57:48

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1042144/only-one-row-editable-on-jtable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!