void () { final JPanel panel = new JPanel(new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), 7, 0)); final JButton btn1 = new JButton(); setDefaults(btn1); btn1.setPreferredSize(new Dimension(100, 20)); final JButton btn2 = new JButton(); setDefaults(btn2); btn2.setPreferredSize(new Dimension(100, 20)); final JButton btn3 = new JButton(); setDefaults(btn3); btn3.setPreferredSize(new Dimension(100, 20)); final JButton btn4 = new JButton(); setDefaults(btn4); btn4.setPreferredSize(new Dimension(100, 20)); panel.add(btn1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.add(btn2, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.add(btn3, new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.add(btn4, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); final Dimension preferredSize = panel.getPreferredSize(); assertEquals(314, preferredSize.width); panel.setSize(panel.getPreferredSize()); panel.doLayout(); }