1
我写一个游戏,我在java中做一个GUI,我有这样的代码:箱布局组件奇怪
private JLabel label = new JLabel("Enter New Level Name");
private JTextField field = new JTextField();
private static JButton createWorld = new JButton("Create World");
private JButton menu = new JButton("Main Menu");
public StartGame()
{
setBackground(Color.CYAN);
Box box = Box.createVerticalBox();
box.add(label);
box.add(Box.createRigidArea(new Dimension(0,10)));
box.add(field);
box.add(Box.createRigidArea(new Dimension(0,10)));
Box hor = Box.createHorizontalBox();
hor.add(createWorld);
hor.add(Box.createRigidArea(new Dimension(10,0)));
hor.add(menu);
box.add(hor);
add(box);
}
我想这个面板看起来像什么是在一个盒子里的所有组件与右边对齐。当我运行这一切时,除了标签以外,其他所有工作都与布局的其余部分不匹配。任何人都可以解释我做错了什么,或者可能的解决方法。
继承人我的问题,我知道它的模糊,但你可以看出,标签是向右偏移。
你能否更详细地解释了如何“标签不与布局的其余部分匹配”? – user0 2013-04-30 21:53:36
它被转移到所有其他compnents的权利,它不排队看图片 – 2013-04-30 21:54:51