Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable column width

 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, some of my columns are more wide than need to be and some are so narrow that the column header name is shortened and followed by dots. How can I make the JTable draw such that every column fits and no column header name is abridged and followed by dots?
 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I think use JTable.setPreferredWidth() for columns will definately help u .....
I have done with the help of that......
pls do tell me if i am missing something
Rishi
 
Eduard Jodas
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should access the TableColumnModel of the JTable. Then access each individual column and set its width. But first of all you should turn off the auto-resize columns capability of the Table.
 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, but should I hard code the widths or should I set the width of each column based on the width of its header name?
 
Eduard Jodas
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's up to you.
Personally, I have hardcoded the widths because some columns are wider than their header name.
 
Alex Gregory
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone, I figured out how to set the widths of the columns.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic