将多个 jPanel 添加到 jFrame
2022-09-03 17:46:49
我想并排向JFrame添加两个jPanel。两个框是jpanels,外框是jframe
我有这些代码行。我有一个名为 seatinPanel 的类,它扩展了 JPanel,在这个类中,我有一个构造函数和一个称为 utilityButtons 的方法,它返回一个 JPanel 对象。我希望实用程序Buttons 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);
}