Solved

how to resize columns of a JTable to automatically fit content

Posted on 2003-10-26
4
800 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet example 17 59
eclipse buid path vs tomcat lib path 10 37
jboss wildfly 10.1 10 405
Is there a simpler dropbox system? 10 44
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

735 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