如何在JTable Invisible for Swing Java中创建一个列

问题描述:

我设计了一个GUI,其中我使用了一个JTable,我必须从中使2个列不可见。我应该怎么做?

I have designed one GUI in which I have used one JTable from which I have to make 2 columns invisible . How should I do that ?

从 TableColumn code> TableColumnModel 。

Remove the TableColumn from the TableColumnModel.

TableColumnModel tcm = table.getColumnModel();
tcm.removeColumn( tcm.getColumn(...) );

如果您需要访问数据,那么您使用 table.getModel() .getValueAt(...)

If you need access to the data then you use table.getModel().getValueAt(...).

对于允许用户隐藏/显示列的更复杂的解决方案,请查看表格栏管理员

For a more complex solution that allows the user to hide/show columns as they wish check out the Table Column Manager.