简体   繁体   English

JDesktopPane占据了整个JFrame

[英]JDesktopPane occupies the entire JFrame

I have a JDesktopPane desktopPane inside a JFrame. 我在JFrame中有一个JDesktopPane desktopPane 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. 我希望此桌面窗格仅占据一定的空间,以便用户可以看到JFrame右侧的内容。 I tried using the method setBounds(...) and setPreferredSize(..) with desktopPane but could not acieve the desired result. 我尝试将方法setBounds(...)setPreferredSize(..)desktopPane一起desktopPane但无法获得所需的结果。 The desktopPane occupies the entire frame and the unused space shows the background color as defined by desktopPane.setBackground(..) . desktopPane占据整个框架,未使用的空间则显示由desktopPane.setBackground(..)定义的背景色。 Is there any way by which I can make the JDesktopPane occupy only the required space in a JFrame? 有什么方法可以使JDesktopPane仅占据JFrame中所需的空间?

JFrame uses a BorderLayout by default, whose default ( CENTER ) position will want to occupy as much of the available space that is available. JFrame默认使用BorderLayout ,其默认位置( CENTER )将要占据尽可能多的可用空间。

JDesktopPane typically has a preferred size of 0x0 , which makes it fine to play with. JDesktopPane通常具有0x0的首选大小,使其可以正常使用。

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. MDI通常希望占据屏幕不动产的最大份额。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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