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

Leave a Reply

Your email address will not be published. Required fields are marked *