我刚开始摆弄BoxLayout管理器。
我将两个按钮放在一起,第三个按钮应该转到下一行(在前两个按钮的下面),前两个按钮应该在框架的顶部。
我如何才能做到这一点呢?
这是我当前的代码
Box box = Box.createHorizontalBox();
box.add(Box.createHorizontalGlue());
box.add(new JButton("Button"));
box.add(new JButton("Hello"));
box.add(Box.createVerticalBox());
box.add(Box.createVerticalStrut(100));
box.add(new JButton("Button2"));
add(box);

发布于 2013-02-14 04:22:05
您当前的代码看起来与您对所需内容的描述完全不同。听起来你需要
- gap
- button
所以就像这样
Box vbox = Box.createVerticalBox();
Box hbox = Box.createHorizontalBox();
hbox.add(new JButton("Button"));
hbox.add(Box.createHorizontalStrut(10));
hbox.add(new JButton("Hello"));
vbox.add(hbox);
vbox.add(Box.createVerticalStrut(100));
vbox.add(new JButton("Button2"));https://stackoverflow.com/questions/14861705
复制相似问题