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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 843
  • Last Modified:

how to resize columns of a JTable to automatically fit content

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
honkinamiland
Asked:
honkinamiland
  • 3
1 Solution
 
jimmackCommented:
Try setPreferredWidth (from TableColumn) for the first two columns.
0
 
jimmackCommented:
and doLayout in JTable (sorry.  That should all have been in one post)
0
 
honkinamilandAuthor Commented:
ok, i needed also to set the max width to make it work, but that's it.
thanks
0
 
jimmackCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now