user502888
user502888

Reputation: 21

Hide column in a JTable

How can we show/hide some columns in JTable?

Upvotes: 0

Views: 6399

Answers (4)

Maxwell Cheng
Maxwell Cheng

Reputation: 1190

When using JXTable from the SwingX project, as suggested by Uhlen,
It's better to use
table.getColumnExt("columnName").setVisible(true); table.getColumnExt("columnName").setVisible(false);
the index when using getColumnExt(index)is the column index that is in the view (i.e.visible)
Once you set a column invisible, you can't access to it by getColumnExt(index)

Upvotes: 1

Uhlen
Uhlen

Reputation: 1778

I recommend JXTable from the SwingX project, hiding columns in the view is very easy:

table.getColumnExt(index).setVisible(false);

JXTable also provides a column control(menu in top-right corner) where user by them selfs can hide/show columns.

Upvotes: 4

Houtman
Houtman

Reputation: 2879

Instead of having to loop through the list for every cell call as shown at codeGuru, you could change the columnModel to switch the column-visibility by setting from/to zero-width and setting editable/noneditable. That wat default handling skips over that column.

Upvotes: 0

Alois Cochard
Alois Cochard

Reputation: 9862

You can find a sample at codeguru:

Don't forget that google is your best friend ...

Upvotes: -1

Related Questions