How to make a columns in JTable Invisible for Swing Java

om. picture om. · Sep 29, 2009 · Viewed 90.3k times · Source

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 ?

Answer

camickr picture camickr · Sep 29, 2009

Remove the TableColumn from the TableColumnModel.

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

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.