Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Swing JDesktopPane with Scrollbars

DZone's Guide to

Swing JDesktopPane with Scrollbars

· Java Zone
Free Resource

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's free.

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

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of Pedro Duque Vieira. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}