Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JScrollPane Dynamic content

843807May 18 2010 — edited May 18 2010
I don't want to call JScrollPane broken, but I have been pulling my hair out for the better part of 2 weeks attempting to understand the best method behind solving this problem.

I havea fairly complex GUI with the following:

JFrame <-- JPanel <--(BorderLayout.CENTER)-- JTabbedPane <-- JScrollPane <-- JPanel <--(SpringLayout)-- Multiple JPanels.

What this means that I have the option to add multiple Jpanels to a panel that is in the JScrollPane etc....

So the problem is this:

The JScrollPane does not allow for scrolling. When JPanels are added, the Panels are visible, but the last of the panels begin to get cut off. JScrollPane doesn't recognize that they have gone out of the view and a scrollbar needs to appear to allow the user to get to them.

What I have done to correct so is to dynamically set the PreferredSize of the JPanel that was added to the JScrollPane each time a new JPanel is added to it. This does get the JScrollPane to behave as I would expect, except it is not an exact fit. Based on the number that I choose increase the height of the PreferredSize the last of the new JPanels is either cut off or there is too much white space.

My expectation is that the JScrollPane would know how big it's viewport is, then determine the Size of the components within it's viewport and set the scrolls accordingly. Since through countless other forums posts over the past decade have indicated that this doesn't happen and that you should set a PreferredSize, is there a series of options to get the "ActualSize" of the component within the JScrollPane. My guess this would be done with a windows listener.

Any help or advice on the matter would be greately appreciated. I will attempt to product a sample application that can be posted in the coming hours.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2010
Added on May 18 2010
3 comments
1,231 views