?
Solved

auto resize jtable column width

Posted on 2005-03-09
8
Medium Priority
?
3,578 Views
Last Modified: 2008-01-09
i have a jtable and i want to be able to auto resize the width of the columns to fit the data.
how do i do this?
0
Comment
Question by:tegz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 13499906
0
 

Author Comment

by:tegz
ID: 13499993
that doesnt resize according to the what i have stored in a particular column
0
 
LVL 4

Expert Comment

by:gdrnec
ID: 13500026
The only way I have seen this done is to get the maximum length string in the column (by iteration and comparison) and use FontMetrics to calculate its size, then set the col width to that size.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:tegz
ID: 13500038
how do i get the maximum length string in a columns though?
any examples?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 13500074
>>
how do i get the maximum length string in a columns though?
any examples?
>>

Scan the table model and:

http://javaalmanac.com/egs/java.awt/TextDim.html
0
 

Author Comment

by:tegz
ID: 13500123
for (int i = 0; i < tb.getColumnCount(); i++)
 {
//get data length, how?
//set column prefered size?
}

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1000 total points
ID: 13501147
0
 

Author Comment

by:tegz
ID: 13502066
i applied: http://javaalmanac.com/egs/javax.swing.table/PackCol.html

didnt change the code, it works all aprt from one long text field.
any ideas why?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question