Swing JDesktopPane with scrollbars

JDesktopPane with scrollbars

For a long time there has been a known issue with Swing’s JDesktopPane. If a JInternalFrame gets out of the viewport, no scrollbars are added and you loose the ability to “reach” the JInternalFrame.

Recently I had to fix this for a project. I searched the web for a simple straight solution to this issue but couldn’t find one so I decided to put my hands on the problem and try to fix it.. I’ve come up with a solution and decided to share it on github.

All you have to do is simply pass a JDesktopPane to this component and add it to a app where you would add the JDesktopPane.

At the base of this problem is the fact that the JDesktopPane doesn’t update its preferred size when the JInternalFrames get out of the viewport. This component will keep track of the JInternalFrames position and add scrollbars when it’s appropriate.

You can grab the code at: https://github.com/dukke/swing-desktopScrollPane

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s