所以我試圖創建一個gui,我之前用java修改過gui,但我對它們還是陌生的。所以我在這裏發佈的是,我的JLabels(但標籤012bcbLabel)充滿了按鈕和複選框。可悲的是我的JFrame只會顯示設置爲BorderLayout.CENTER的設置。 NORTH不會顯示,即使我只將butLabel設置爲SOUTH,甚至不使用cbLabel。我忽略了什麼?非常感謝,謝謝!JButtons只出現在JFrame上,如果在BorderLayout.CENTER中,不是SOUTH或NORTH
public class mainWindow
{
JFrame frame = new JFrame("Main Window");
JLabel butLabel = new JLabel();
JLabel cbLabel = new JLabel();
JButton showBut = new JButton("Show");
JButton exitBut = new JButton("Exit");
JButton addBut = new JButton("Add");
JButton remBut = new JButton("Remove");
JCheckBox aCB = new JCheckBox("Airplane");
JCheckBox bCB = new JCheckBox("Boat");
JCheckBox cCB = new JCheckBox("Clock");
public mainWindow()
{
frame.setLayout(new BorderLayout()); //I know this is set by default to BorderLayout but I just did it when I was out of options to try.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(360, 480));
butLabel.setLayout(new GridLayout(1,4));
cbLabel.setLayout(new GridLayout(2, 2));
butLabel.add(showBut);
butLabel.add(exitBut);
butLabel.add(addBut);
butLabel.add(remBut);
cbLabel.add(aCB);
cbLabel.add(bCB);
cbLabel.add(cCB);
frame.add(butLabel, BorderLayout.CENTER);
frame.add(cbLabel, BorderLayout.NORTH);
}
public void setVisible()
{
butLabel.setVisible(true);//Didn't think I needed butLabel.setVisible or the cbLabel.setVisible but
cbLabel.setVisible(true);//again I was trying things that I thought might make sense.
frame.setVisible(true);
}
}
不使用標籤分組元素,而是使用JPanel而不是 – maskacovnik 2014-10-19 19:18:19
好天啊我真不敢相信我做了這些,我以前看過它,看起來不正確。善良,我感到很傻。謝謝你的快速反應! – 2014-10-19 19:19:59
很高興 – maskacovnik 2014-10-19 19:20:33