• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

How to hide columns in a JTable ?!!

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Ranch Hand
Posts: 147
Python Ruby Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have to set max and min to 0, just the preferred width of the column.
table.getColumnModel().getColumn(3).setPreferredWidth(0);
 
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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.
 
You'll never get away with this you overconfident blob! The most you will ever get is this tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!