void () { final GridLayoutManager layoutManager = new GridLayoutManager(2, 3, new Insets(0, 0, 0, 0), 0, 0); final JPanel panel = new JPanel(layoutManager); final JButton button = new JButton(); setDefaults(button); button.setPreferredSize(new Dimension(50, 10)); final JTextField field1 = new JTextField(); setDefaults(field1); field1.setPreferredSize(new Dimension(110, 10)); final JTextField field2 = new JTextField(); setDefaults(field2); field2.setPreferredSize(new Dimension(110, 10)); panel.add(button, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.add(field1, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.add(field2, new GridConstraints(1, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); panel.doLayout(); final Dimension preferredSize = panel.getPreferredSize(); // field will be not null after getPreferredSize() final DimensionInfo horizontalInfo = layoutManager.myHorizontalInfo; assertEquals(GridConstraints.SIZEPOLICY_WANT_GROW | GridConstraints.SIZEPOLICY_CAN_GROW, horizontalInfo.getCellSizePolicy(0)); assertEquals(GridConstraints.SIZEPOLICY_CAN_SHRINK, horizontalInfo.getCellSizePolicy(1)); assertEquals(GridConstraints.SIZEPOLICY_WANT_GROW, horizontalInfo.getCellSizePolicy(2)); assertEquals(220, preferredSize.width); panel.setSize(new Dimension(500, panel.getHeight())); panel.doLayout(); assertEquals(250, button.getWidth()); assertEquals(250, field1.getWidth()); assertEquals(250, field2.getWidth()); }