我正在用 Java 开发 GUI。我有几个问题希望得到帮助,希望你们中的一些人能够提供帮助。
您可能需要下面的图片:
1.. 条目之间的空格:我希望将其删除。现在,每个条目都是一个 GridLayout 为 2,1 的 JPanel。每行都有另一个 JPanel(line1 和 line2)。默认情况下,第 2 行是隐藏的,并且仅在单击编辑按钮时显示,然后在再次单击时隐藏。我可以使用 setVisible() 更改可见性。但它创造了那么大的空间。
[已解决] 2.. Line2 有一个 FlowLayout,我怎样才能让它左对齐?
3.. 每个条目都是类(称为“Preset”),并存储在称为“presetListing”的类变量数组中。当我单击“新分支”按钮时,我创建一个容量为 +1 的新阵列,将所有旧预设转移进来,并在最后一个空间中创建一个新预设。我需要做什么才能让新条目显示在 GUI 中?我尝试将其添加到 JPanel,然后 validate(),但没有成功。
希望有人能够帮助我,先谢谢了!
编辑: 这是#3 中的代码:
private void newBranch(){
Preset[] tempBranches = new Preset[branches.length + 1];
for (int i = 0; i < branches.length; i++){
tempBranches[i] = branches[i];
}
tempBranches[branches.length] = new Preset();
branches = tempBranches;
pane = new JPanel();
pane.setLayout(new GridLayout(branches.length, 1));
for (int i = 0; i < branches.length; i++){
pane.add(branches[i]);
}
scroller = new JScrollPane(pane);
this.add(scroller, BorderLayout.CENTER);
this.repaint();
this.validate();
}
最佳答案
这应该可以用子面板填充面板:
for (int i = 0; i <= _listElements.size(); i++) {
_panel.add(_listElements.get(i), new GridBagConstraints(0, i, 1, 1, 0, 0,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
}
关于java - 如何删除 JFrame 中的空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957397/