1

I want to create a table, for example, that has 3 column headers but only shows two columns and hiding the 3rd.

The last column is fixed and used to hide/show columns like most of applications do by clicking it and showing a popup menu.

Cheers

probably I didn't describe clearly. I know removeColumn/addColumn. By clicking on the table header, i can add column or remove them. However what I am curious is that a dedicated column header at the most right corner of the table header, which is fixed, small width and with descriptive table-like icon. So, by left mouse clicking this column header, a popup menu shows up for hiding/showing columns.This column header doesn't actually have column or rows but the header, like JDownloader does.

4

3 回答 3

4

你看过,JTable 方法

这两种方法只是为了隐藏/显示JTables Column(s),数据在TableModel

于 2012-06-04T16:29:00.503 回答
3

JXTableof具有用于在弹出窗口中显示/隐藏列的SwingX内置 UI(不幸的是,我找不到它的图像)。

您当然可以使用建议的方法自己创建它,但为什么要重新发明轮子

于 2012-06-04T18:31:51.957 回答
2

有两种方法可以做到这一点:

正确的方法:

从表中删除列

TableColumn lastColumn = table.getColumnModel().getColumn(lastIndex);
table.removeColumn(lastColumn);

不要这样做:

将最后一列的宽度设置为 0:

table.getColumnModel().getColumn(lastIndex).setPrefferedWidth(0);
table.getColumnModel().getColumn(lastIndex).setMaximumWidth(0);
table.getColumnModel().getColumn(lastIndex).setMinimumWidth(0);
于 2012-06-04T16:26:41.153 回答