我有一个JFrame
. GridBagLayout
weightx 和 weighty 值被分配不同的非零值并且 GridBagConstraints.fill = GridBagConstraints.BOTH。我在其中一个单元格中嵌套了一个 JPanel,并给了它一个 GridBagLayout。将组件添加到嵌套的 JPanel 时,嵌套的 JPanel 所在的单元格大小会在缺少父布局的所有边上增长。不使用插入和填充。
我该如何解决这个问题?谢谢。这是 GridBagConstraints 值的示例:
GridBagConstraints treePanCon = new GridBagConstraints();
treePan.setLayout(treePanGridbag);
treePanCon.fill = GridBagConstraints.BOTH;
treePanCon.weightx = 0.5;
treePanCon.weighty = 1;
treePanCon.gridx = 0;
treePanCon.gridy = 0;
treePanCon.gridwidth = 1;
treePanCon.gridheight = 1;
这是向嵌套的 JPanel 添加组件之前的屏幕截图:
这是将组件添加到嵌套 JPanel 后的屏幕截图: