JTable上只有一行可编辑 [英] Only one row editable on JTable

查看:110
本文介绍了JTable上只有一行可编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一种特殊的jtable.我希望整个表默认情况下不可编辑.但是,当用户单击一行,然后单击编辑" jbutton时,该特定行是可编辑的.并且一旦他们忽略了该行,便无法再对其进行编辑.

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.

我该怎么做?

推荐答案

要控制哪些单元格是可编辑的,您将需要扩展JTable或JTableModel(请参见下面的示例中的模型调用)以确保此方法对于希望根据规范进行编辑的行中的所有单元格,JTable中的from from JTable都会返回true.

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));
  }

还请参见本教程了解TableCellEditors

also take a look at this tutorial to learn about TableCellEditors

这篇关于JTable上只有一行可编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆