Reputation: 21
How can we show/hide some columns in JTable?
Upvotes: 0
Views: 6399
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
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
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
Reputation: 9862
You can find a sample at codeguru:
Don't forget that google is your best friend ...
Upvotes: -1