我想将两个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