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