• Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto Sizing JTable Columns

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, here was my first idea. Just before I actually display the JTable I have created, I will pull all the values from each column, find the longest cell, and size the column based on that length.
So now for my question(s).
Once I get the lengths of my values, since they are just text, how do I convert to pixals so I know how wide to set my columns?
Is there an easier way to do what I am wanting to do than how I decided to do it?
 
Shane Roylance
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the FontMetrics object to find the widths of your characters in pixels. Or if you just wanted to err on the big side use:

Hopefully that is helpful.
[ July 01, 2002: Message edited by: Shane Roylance ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!