我想將兩個jPanel並排添加到JFrame中。兩個盒子是jpanels,外盒子是一個jframe 將多個jPanel添加到jFrame中
我有這幾行代碼。我有一個名爲seatinPanel的類,它擴展了JPanel,在這個類中我有一個構造函數和一個名爲utilityButtons的方法,它們返回一個JPanel對象。我希望utilityButtons JPanel位於右側。我在這裏的代碼只在運行時顯示utillityButtons JPanel。
public guiCreator()
{
setTitle("Passenger Seats");
//setSize(500, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentPane = getContentPane();
seatingPanel seatingPanel1 = new seatingPanel();//need to declare it here separately so we can add the utilityButtons
contentPane.add(seatingPanel1); //adding the seats
contentPane.add(seatingPanel1.utilityButtons());//adding the utility buttons
pack();//Causes this Window to be sized to fit the preferred size and layouts of its subcomponents
setVisible(true);
}
當我嘗試這樣做時,它給了我這個錯誤BoxLayout不能共享 – dave 2011-06-12 23:52:39
@dave:對不起,我的錯。我現在編輯我的答案。 – Heisenbug 2011-06-12 23:58:56
感謝它現在工作 – dave 2011-06-13 00:06:34