使用GridBagLayout将JDesktopPane添加到JFrame [英] Adding JDesktopPane to JFrame using GridBagLayout
问题描述
如何使用GridBagLayout
将JDesktopPane
添加到JFrame
并设置其高度和宽度.如果添加包含JInternalFrame
的JDesktopPane
,我什么也不会得到.但是在GridLayout
的情况下效果很好,但是问题是我无法在其中设置所需的大小,因为GridLayout
在添加的每个组件之间分配相等的空间.
How do I add the JDesktopPane
to JFrame
using GridBagLayout
and set its height and width. If I add JDesktopPane
that contains JInternalFrame
I don't get anything. But works well in case of GridLayout
but the problem is I can't set my desired size in it as GridLayout
splits equal space among each component added.
推荐答案
您可能需要设置GridBagConstraints
...
You will probably need to set the fill and weight attributes of the GridBagConstraints
...
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
这将导致组件想将其推到容器的极限,并使组件填充其网格内的单元格
This will cause the component to want to push to the limits of the container and will cause the component to fill it's cell within the grid
这将覆盖组件的首选大小(大部分情况下)
This override the components preferred size (for the most part)
有关更多信息,请参见如何使用GridBagLayout 详细信息...
Take a look at How to Use GridBagLayout for more details...
这篇关于使用GridBagLayout将JDesktopPane添加到JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!