如何使用JDesktopPane
将JFrame
添加到GridBagLayout
并设置其高度和宽度。如果我添加包含JDesktopPane
的{{1}},我什么都得不到。但是在JInternalFrame
的情况下运行良好,但问题是我无法在其中设置所需的大小,因为GridLayout
在添加的每个组件之间分割相等的空格。
答案 0 :(得分:3)
您可能需要设置GridBagConstraints
...
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;
这会导致组件想要推到容器的极限并导致组件填充网格中的单元格
这会覆盖组件首选大小(大部分)
请查看How to Use GridBagLayout了解更多详情......