This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Auto-Resize JTable columns based on content Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Auto-Resize JTable columns based on content" Watch "Auto-Resize JTable columns based on content" New topic
Author

Auto-Resize JTable columns based on content

Jayes Herryl
Greenhorn

Joined: Jun 09, 2006
Posts: 7
Hi,

I try to make a JTable adjust its column widths based on the content of the column when the table is initialized.

Apparently the setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS) does not help. Is there a way to make the table smart enough to shrink the widths on columns with more room, and expand those with more contents in the grids?

Any advice is much appreciated!
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10747
    
    9

This is what you need.
http://jroller.com/santhosh/entry/packing_jtable_columns

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 5046
    
  10

Yuo could also check out Rob Camick's blog entry Table Column Adjuster or my Spring Table posted on another forum.


luck, db
There are no new questions, but there may be new answers.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10747
    
    9

The SpringTable is a neat trick.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Auto-Resize JTable columns based on content
 
It's not a secret anymore!