This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable setMinimumSize problem  RSS feed

 
Jayes Herryl
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTable, which will auto-adjust its column widths based on the data in the cells. And to make this work I have to turn auto resize off by calling table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

The table sits in a JPanel with certain width.

The problem is that with auto_resize_off, when initially there is no data in the table or when the data in the grid is not long enough, the table will not expand across the entire width of the JPanel. So there is an empty gap between the right-end of the table and the right edge of the JPanel.
So I tried to do table.setMinimumSize(new Dimension(MyJPanelWidth, whateverHeight)) to make the initial width of the table same as that of the JPanel. But it does not work! Nothing gets changed for the table width.

However, table.setPreferredSize will change the table width, but my table will not auto-expand its columns, which does not serve my purpose either.

So my question is -- how do I set the initial/minimum table width without impacting its ability to auto-adjust its columns based on data?

Any advice is much appreciated!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
iterate the columns, setting width for each



where [width] could be the preferredSize of the scrollPane or panel,
divided by the columnCount
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!