aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Column sizing in JScrollPane Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Column sizing in JScrollPane" Watch "Column sizing in JScrollPane" New topic
Author

Column sizing in JScrollPane

Derek Drever
Greenhorn

Joined: Mar 01, 2002
Posts: 18
Hi Guys,
If any of you could help I would be grateful:
I have an application with a fixed window size, within this I have a JTabbedPane, each tab contains a JScrollPane which contains a JTable. The tables can have different numbers of columns. I am trying to achieve a uniform look and this is where I am having problems.
I set the columns to a minimum width. If there are few columns, less than the width of the JScrollPane, I would like the columns to resize to fill the scroll pane. This is acheivable by setting the auto resize mode to AUTO_RESIZE_ALL_COLUMNS.
If there are many columns I would like a horizontal scroll bar, this is achieved by setting the auto resize mode to AUTO_RESIZE_OFF, however to achieve both automatically is the problem.
You can achieve this effect by placing the table in a JPanel and adding the panel to the scroll pane but then you lose the column headings.
I would settle for being able to detect the size of the viewport, then I could calculate the minimum column size * the number of columns and set the resize mode accordingly. However when I get the viewport associated with the scroll pane I canot get its size (I used viewport.getExtentSize()), it always comes back with a width and height of 0.
Any ideas would be appreciated.
Regards,
Derek Drever
Derek Drever
Greenhorn

Joined: Mar 01, 2002
Posts: 18
Found a solution on another forum, just extend JTable and override the following method - works a treat.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Column sizing in JScrollPane