Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hiding columns in JTable

 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you hide more than one column and make it/them return when you want???
 
Meghna ks
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(no. of the col you want to hide);
column1.setMaxWidth(0);
column1.setMinWidth(0);
column1.setWidth(0);
column1.setPreferredWidth(0);
Hi keiyia .. You could try this code to hide the column you want.
To unhide them, you could try the same code & set the max, min, width & preferredwidths to the required dimension in the condition you want the columns to show.
for eg;
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(no. of the col you want to hide);
column1.setMaxWidth(100);
column1.setMinWidth(10);
column1.setWidth(100);
column1.setPreferredWidth(100);
Thanks
Meghna
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the capability of hiding them, but just can't get them back.
ok, here's the situation:
i have a split pane witha table on one side. on the menubar is a view option. it has 4 checkbox menuitems. i need for the the appearance to change everytime an item is selested or deselected. if selected, it needs to be hidden (which i already had). if deselcted, return as to original state (which i can't get to worked).
 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try out !!!
To hide a Column<Column No>

To enable the Column (i.e width =100)<Column No>

write the code in selection of the menu.
Onselection use enable code.
Deselection use hide code.
This code works for me.

 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whether width = 0 or required size

 
Javaoops
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whether width = 0 or required size
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is another way of doing it. Sets the 1st column to invisible.
DefaultTableColumnModel columnModel = new DefaultTableColumnModel() {
public void addColumn(TableColumn tc) {
boolean first = true;
if (first) {
first = false;
return;
}
super.addColumn(tc);
}
};
table.setColumnModel(columnModel);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic