JTable 上只能编辑一行

发布于 2024-07-25 05:32:20 字数 121 浏览 2 评论 0原文

我正在尝试制作一种特殊的 jtable。 我希望整个表默认不可编辑。 但是,当用户单击一行,然后单击“编辑”j 按钮时,该特定行是可编辑的。 一旦他们取消选择该行,它就不再可编辑。

我该怎么做呢?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

開玄 2024-08-01 05:32:20

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

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

另请查看本教程来学习关于表格单元格编辑器

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文