Solution: nest JPanels
Create a 3rd JPanel, one that uses BoxLayout oriented to BoxLayout.PAGE_AXIS, add your 2 JPanels to this, and then add this third JPanel to the main GUI (which hopefully uses BorderLayout) to the BorderLayout.PAGE_END position.
For example, my Minimal, Complete, and Verifiable Example Program:
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.*;
public class LayoutExample extends JPanel {
public LayoutExample() {
JPanel panel1 = new JPanel();
panel1.add(new JLabel("Label 1"));
panel1.add(new JTextField(10));
panel1.setBorder(BorderFactory.createTitledBorder("Panel 1"));
JPanel panel2 = new JPanel();
panel2.add(new JLabel("Label 2"));
panel2.add(new JTextField(10));
panel2.setBorder(BorderFactory.createTitledBorder("Panel 2"));
JPanel boxLayoutUsingPanel = new JPanel();
boxLayoutUsingPanel.setLayout(new BoxLayout(boxLayoutUsingPanel, BoxLayout.PAGE_AXIS));
boxLayoutUsingPanel.add(panel1);
boxLayoutUsingPanel.add(panel2);
boxLayoutUsingPanel.setBorder(BorderFactory.createTitledBorder("BoxLayout Panel"));
setLayout(new BorderLayout());
setBorder(BorderFactory.createTitledBorder("Main BorderLayout GUI"));
add(Box.createRigidArea(new Dimension(400, 200)), BorderLayout.CENTER);
add(boxLayoutUsingPanel, BorderLayout.PAGE_END);
}
private static void createAndShowGui() {
LayoutExample mainPanel = new LayoutExample();
JFrame frame = new JFrame("LayoutExample");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}
If still stuck, create and post your Minimal, Complete, and Verifiable Example Program.