Hello, 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 ?
Set the min, max and "normal" width to 0:
jTable.getColumn("ABC").setWidth(0);
jTable.getColumn("ABC").setMinWidth(0);
jTable.getColumn("ABC").setMaxWidth(0);
The second approach is to extend TableColumnModel
and override all the methods to create the illusion (for the JTable) that your model doesn't have those two columns.
So when you hide a column, you must return one less when the table asks for the number of columns and when it asks for the column X, you may have to add +1 to the column index (depending on whether it is to the left or right of the hidden column), etc.
Let your new table model forward all method calls (with the corrected indexes, etc) to the actual column model and use the new table model in the JTable.
You could create a subclass of the model, and override TableModel.getColumnCount as follows:
int getColumnCount() { return super.getColumnCount()-2; }
The last two columns would then not be displayed in the JTable.
Remove the TableColumn from the TableColumnModel.
If you need access to the data then you use table.getModel().getValueAt(...).