【发布时间】:2018-06-09 04:40:58
【问题描述】:
我正在尝试使用 MigLayout 创建一个面板,分为三行。第一行和最后一行的 pushY 应为某个比率(在本例中为 2f),中间的行应尽可能增长以占据剩余空间。
但是,在某些情况下,最后一行(例如,它本身就是一个面板)中没有任何组件。在这种情况下,我希望第二行占据所有高度,但我无法实现。
请注意,由于其他流相关性,使其不可见是不可能的。
我已在此处附上代码:
public class TestClass {
public static void main(String[] args) {
createPanel(true);
createPanel(false);
}
private static void createPanel(boolean removeAll) {
JFrame frame = new JFrame();
JPanel panel = new JPanel(new MigLayout(new LC().fill().gridGap("0", "0").insetsAll("0")));
panel.add(new JLabel("first row"), new CC().grow().newline().pushY(2f));
JTextArea abc = new JTextArea("abc");
abc.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
panel.add(abc, new CC().push().grow().newline());
JPanel pnl = new JPanel(new MigLayout(new LC().fill().gridGap("0", "0").insetsAll("0")));
pnl.add(new JLabel("aaa"), new CC());
pnl.add(new JLabel("bbb"), new CC().newline());
pnl.add(new JLabel("ccc"), new CC().newline());
panel.add(pnl, new CC().grow().newline().pushY(2f));
if (removeAll) {
pnl.removeAll();
}
frame.setContentPane(panel);
frame.setSize(100,800);
frame.setVisible(true);
}
}
【问题讨论】:
标签: java swing layout-manager miglayout