使用GridBagLayout将JDesktopPane添加到JFrame

时间:2014-04-04 22:44:47

标签: java swing jframe jinternalframe jdesktoppane

如何使用JDesktopPaneJFrame添加到GridBagLayout并设置其高度和宽度。如果我添加包含JDesktopPane的{​​{1}},我什么都得不到。但是在JInternalFrame的情况下运行良好,但问题是我无法在其中设置所需的大小,因为GridLayout在添加的每个组件之间分割相等的空格。

1 个答案:

答案 0 :(得分:3)

您可能需要设置GridBagConstraints ...

的填充和重量属性
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;

这会导致组件想要推到容器的极限并导致组件填充网格中的单元格

这会覆盖组件首选大小(大部分)

请查看How to Use GridBagLayout了解更多详情......