Assuming two panels are added to the same frame:
Set the layout for the parent JFrame and add two panels. Something like the following
JFrame frame = new JFrame(); //frame.setLayout(); - Set any layout here, default will be the form layout JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); frame.add(panel1); frame.add(panel2);
Assuming you want to add one panel on top of another
JFrame frame = new JFrame(); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel(); frame.add(panel1); panel1.add(panel2);
There is no limit to the number of panels added to the JFrame. You must understand that they are all containers when they are seen at a higher level.
source share