JLabel label = new JLabel("Hello World"); label.setMinimumSize(new Dimension(100, 50));
JPanel panel = new JPanel(new GridLayout(2, 2)); JLabel label1 = new JLabel("Label 1"); label1.setMinimumSize(new Dimension(50, 50)); JLabel label2 = new JLabel("Label 2"); label2.setMinimumSize(new Dimension(50, 50)); JLabel label3 = new JLabel("Label 3"); label3.setMinimumSize(new Dimension(50, 50)); JLabel label4 = new JLabel("Label 4"); label4.setMinimumSize(new Dimension(50, 50)); panel.add(label1); panel.add(label2); panel.add(label3); panel.add(label4);In both examples, we are using the javax.swing package library.