• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing table header  RSS feed

 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
I'm wondering if you know how to set a table header width, with values that I want for each column. I'm trying to look for samples with JTable and JTableHeader (how this things work together?).
Thanks.
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial has a section on How to use Tables, and it says:

To customize initial column widths, you can invoke setPreferredWidth on each of your table's columns. This sets both the preferred widths of the columns and their approximate relative widths.

No shortage of examples there, either.
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe, I got a quite simple solution from there:
_table.getColumnModel().getColumn(0).setPreferredWidth(50);
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Swing forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!