我有一个JFrame
与GridBagLayout
。 weightx和weighty值被分配了不同的非零值,并且GridBagConstraints.fill = GridBagConstraints.BOTH。我在一个单元格中嵌套了一个JPanel,并给它一个GridBagLayout。向嵌套JPanel添加组件时,嵌套JPanel所在位置的单元格大小在所有侧缺少父级布局。不使用插入和填充。
我该如何解决这个问题?谢谢。 这是GridBagConstraints的值的示例:与GridBagLayout嵌套的JPanel
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后的屏幕截图:
你能包含代码吗?你能描述一下你想要发生什么吗? – eon