简体   繁体   中英

JDesktopPane occupies the entire JFrame

I have a JDesktopPane desktopPane inside a JFrame. I want this desktoppane to occupy only a certain space so that the contents in the right of the JFrame is visible to the user. I tried using the method setBounds(...) and setPreferredSize(..) with desktopPane but could not acieve the desired result. The desktopPane occupies the entire frame and the unused space shows the background color as defined by desktopPane.setBackground(..) . Is there any way by which I can make the JDesktopPane occupy only the required space in a JFrame?

JFrame uses a BorderLayout by default, whose default ( CENTER ) position will want to occupy as much of the available space that is available.

JDesktopPane typically has a preferred size of 0x0 , which makes it fine to play with.

You could try other layout managers, but you will need to first overcome the issue of the default preferred size.

See Laying Out Components Within a Container for more details

The question is though, why? A MDI typically wants to take the lion share of the screen real estate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM