This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to hide columns in a JTable ?!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to hide columns in a JTable ?!!" Watch "How to hide columns in a JTable ?!!" New topic
Author

How to hide columns in a JTable ?!!

Sandhya
Greenhorn

Joined: Feb 28, 2001
Posts: 3
Hi How do I hide only some columns in a JTable.I tried the following code
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(2); column1.setMaxWidth(0);
column1.setMinWidth(0);
column1.setWidth(0);
column1.setResizable(false);
But, it is having ... in the table header and the table looks real ugly now.
Thanks
Sandhya
Sandhya
Greenhorn

Joined: Feb 28, 2001
Posts: 3
Okay people, I found a way to do this .. ALong with setting the column min, max and widths to 0, you also need to setPreferredWidth to 0 also.
Originally posted by Sandhya:
Hi How do I hide only some columns in a JTable.I tried the following code
TableColumn column1 = null;
column1 = JTable1.getColumnModel().getColumn(2); column1.setMaxWidth(0);
column1.setMinWidth(0);
column1.setWidth(0);
column1.setResizable(false);
But, it is having ... in the table header and the table looks real ugly now.
Thanks
Sandhya

Glen Tanner
Ranch Hand

Joined: Apr 16, 1999
Posts: 147

You don't have to set max and min to 0, just the preferred width of the column.
table.getColumnModel().getColumn(3).setPreferredWidth(0);
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
"Sandhya",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
Thanks.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to hide columns in a JTable ?!!
 
Similar Threads
Runtime Creating Tables
Advanced understanding of JTables
Hiding columns in JTable
Hiding JTable Columns
The problem still persists