我想在一个JFrame中并排添加两个JPanel。这两个盒子是JPanel,外部盒子是JFrame
我有以下代码。我有一个名为seatinPanel的类,它继承了JPanel,在这个类中我有一个构造函数和一个名为utilityButtons的方法,该方法返回一个JPanel对象。我希望utilityButtons JPanel在右侧显示。但是,我现在运行此代码时只会显示utilityButtons 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);
}