I would like to have three JPanel p1 p2 and p3 and lay them out like this:

I play with FlowLayout, BoxLayout, etc., but I'm not sure I'm going in the right direction. I am new to Java, so I donβt know what it does, to be honest.
I like the way BoxLayout works by resizing panels, but I would like to be able to assign it some kind of width attribute.
I do not use a visual constructor for this, this is my window code at the moment:
private void initialize() { Dimension dimensions = Toolkit.getDefaultToolkit().getScreenSize(); frame = new JFrame(); frame.setLayout(new GridLayout(1, 3)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(dimensions.width / 2 - WINDOW_WIDTH / 2, dimensions.height / 2 - WINDOW_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT); JPanel p1 = new JPanel(new BorderLayout()); p1.setBackground(Color.red); JPanel p2 = new JPanel(new BorderLayout()); p2.setBackground(Color.black); JPanel p3 = new JPanel(new BorderLayout()); p3.setBackground(Color.blue); frame.add(p2); frame.add(p1); frame.add(p3); }
Any pointers appreciated!
EDIT: I managed to get it working as I wanted thanks to mKorbel. The right column is not laid out exactly as I was going to do it, but I really changed my mind and decided to save a different layout.

The code:
import java.awt.*; import javax.swing.*; public class PanelWindow extends JFrame { private static final long serialVersionUID = 1L; private static final int WINDOW_HEIGHT = 600; private static final int WINDOW_WIDTH = 800; private JPanel p1, p2, p3; public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { PanelWindow panelWindow = new PanelWindow(); } }); } public PanelWindow() { initialize(); } private void initialize() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); p1 = new JPanel(); p1.setBackground(Color.red); p2 = new JPanel(); p2.setBackground(Color.green); p3 = new JPanel(); p3.setBackground(Color.blue); gbc.gridx = gbc.gridy = 0; gbc.gridwidth = gbc.gridheight = 1; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.weightx = gbc.weighty = 97; gbc.insets = new Insets(2, 2, 2, 2); add(p1, gbc); gbc.gridy = 1; gbc.weightx = gbc.weighty = 3; gbc.insets = new Insets(2, 2, 2, 2); add(p2, gbc); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 2; gbc.weightx = 20; gbc.insets = new Insets(2, 2, 2, 2); add(p3, gbc); pack(); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Dimension dimensions = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(dimensions.width / 2 - WINDOW_WIDTH / 2, dimensions.height / 2 - WINDOW_HEIGHT / 2, WINDOW_WIDTH, WINDOW_HEIGHT); setTitle("Panel Window"); } }