import java.awt.BorderLayout; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.JPanel; public class NewJFrame extends javax.swing.JFrame { public NewJFrame() { JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS)); mainPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.RED), "mainPanel")); //for the top panel (1 big white square label and 2 sub-panels) JPanel topPanel = new JPanel(); topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS)); topPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("topPanel")); JLabel label1 = new JLabel(); label1.setBorder(javax.swing.BorderFactory.createLineBorder(Color.BLACK)); label1.setMaximumSize(new java.awt.Dimension(142, 142)); label1.setMinimumSize(new java.awt.Dimension(142, 142)); label1.setPreferredSize(new java.awt.Dimension(142, 142)); //first subPanel, with 2 text labels inside JPanel subPanel1 = new JPanel(); subPanel1.setLayout(new BoxLayout(subPanel1, BoxLayout.PAGE_AXIS)); subPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("")); JLabel label2 = new JLabel("label2"); JLabel label3 = new JLabel("label3"); subPanel1.add(label2); subPanel1.add(label3); //second subpanel, also 2 text labels inside JPanel subPanel2 = new JPanel(); subPanel2.setLayout(new BoxLayout(subPanel2, BoxLayout.PAGE_AXIS)); subPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("")); JLabel label4 = new JLabel("label4"); JLabel label5 = new JLabel("label5"); subPanel2.add(label4); subPanel2.add(label5); //add everything to topPanel topPanel.add(label1); topPanel.add(subPanel1); topPanel.add(subPanel2); //for the bottom panel (2 subpanels inside) JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS)); bottomPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("bottomPanel")); //third subPanel, 2 labels JPanel subPanel3 = new JPanel(); subPanel3.setLayout(new BoxLayout(subPanel3, BoxLayout.PAGE_AXIS)); subPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("")); JLabel label6 = new JLabel("label6"); JLabel label7 = new JLabel("label7"); subPanel3.add(label6); subPanel3.add(label7); //fourth subPanel, 2 labels JPanel subPanel4 = new JPanel(); subPanel4.setLayout(new BoxLayout(subPanel4, BoxLayout.PAGE_AXIS)); subPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("")); JLabel label8 = new JLabel("label8"); JLabel label9 = new JLabel("label9"); subPanel4.add(label8); subPanel4.add(label9); //add everything to bottomPanel bottomPanel.add(subPanel3); bottomPanel.add(subPanel4); //add both topPanel and bottomPanel to mainPanel mainPanel.add(topPanel); mainPanel.add(bottomPanel, BorderLayout.WEST); //add to the left side of content pane getContentPane().add(mainPanel, BorderLayout.WEST); pack(); } public static void main(String args[]) { new NewJFrame().setVisible(true); } }