简体   繁体   English

JTable上只能编辑一行

[英]Only one row editable on JTable

I am trying to make a special kind of jtable. 我想制作一种特殊的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. 但是当用户单击一行时,然后单击“编辑”j按钮,该特定行是可编辑的。 and once they deslect the row its no longer editable. 一旦他们选择了行,它就不再可编辑了。

How would I go about doing this? 我该怎么做呢?

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. 要控制哪些单元格是可编辑的,您需要扩展JTable或JTableModel(请参阅下面示例中对模型的调用),以确保JTable中的此方法对您想要编辑的行中的所有单元格返回true根据您的规格。

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

also take a look at this tutorial to learn about TableCellEditors 另请参阅本教程以了解TableCellEditors

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM