aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Hiding columns in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Hiding columns in JTable" Watch "Hiding columns in JTable" New topic
Author

Hiding columns in JTable

keiyia jackson
Ranch Hand

Joined: Jul 16, 2001
Posts: 49
How do you hide more than one column and make it/them return when you want???
Meghna ks
Ranch Hand

Joined: Mar 15, 2001
Posts: 122
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

Joined: Jul 16, 2001
Posts: 49
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

Joined: Jun 21, 2001
Posts: 57
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

Joined: Jun 21, 2001
Posts: 57

Whether width = 0 or required size

Javaoops
Ranch Hand

Joined: Jun 21, 2001
Posts: 57

Whether width = 0 or required size
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hiding columns in JTable