0

要隐藏(使不可见)TableColumns 通常这样做:

TableColumn.setMinWidth(0);
TableColumn.setMaxWidth(0);

或使用 removeColumn 方法(列)从模型中删除;

但是在运行时,我们需要使列不可见或可见,最终使用setMinWidth (0) 和 setMaxWidth (0)更加实用。

这会产生一个问题,因为如果用户选择表格行并按Ctrl+C并将其粘贴到文本文件中,它可以复制隐藏列的值!!!

我们可以使用TransferHandler不执行 JComponent 的 CopyAction来解决问题。如何 TableColumn is not a JComponent 不会给出以这种方式解决的。

另一种选择是定义:(JTable 禁止选择行)

JTable.setRowSelectionAllowed(false)

Well this last solution would not be feasible for me because I need to keep the permit selection of rows in the table. Does anyone have another solution to restrict copying of values ​​from all the columns?

4

1 回答 1

2

要隐藏(使不可见)TableColumns 通常这样做:

TableColumn.setMinWidth(0);
TableColumn.setMaxWidth(0);
  • 这不是好方法,使用零大小,此列不隐藏,只有 un_natural 大小,仍然可以访问所有鼠标和键事件

  • 你必须removeColumn()JTables view

于 2014-01-07T10:51:58.923 回答