Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

auto resize jtable column width

Posted on 2005-03-09
8
Medium Priority
?
3,593 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
  • 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
Industry Leaders: 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!

 

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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

564 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