Solved

how to resize columns of a JTable to automatically fit content

Posted on 2003-10-26
4
807 Views
Last Modified: 2007-12-19
hi,
i have a jtable, that has three columns. in the first two there is only a number, the last one contains a string. right now every column hast the same size and there is not enough space for the string. how can i make the table to decrease the the with for the first two columns?
0
Comment
Question by:honkinamiland
[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
  • 3
4 Comments
 
LVL 15

Accepted Solution

by:
jimmack earned 150 total points
ID: 9623934
Try setPreferredWidth (from TableColumn) for the first two columns.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9623935
and doLayout in JTable (sorry.  That should all have been in one post)
0
 

Author Comment

by:honkinamiland
ID: 9623964
ok, i needed also to set the max width to make it work, but that's it.
thanks
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9623971
Just in case you need more, there's a good example here:

http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom

It's the example after the "Version note" after this heading.
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
CSV file parsing thru Java 13 54
ejb entity bean example 2 57
Java syntax, or is it Selenium 6 59
Java array 10 86
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

734 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