void () { final GridLayoutManager layoutManager = new GridLayoutManager(2,3, new Insets(0,0,0,0), 0, 0); final JPanel panel = new JPanel(layoutManager); // empty textfield(span 2) // textfield(span 2) empty final JTextField field1 = new JTextField(); field1.setPreferredSize(new Dimension(100,30)); final JTextField field2 = new JTextField(); field2.setPreferredSize(new Dimension(100,30)); panel.add(field1, new GridConstraints(0,1,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(0,0), null, null, 0)); panel.add(field2, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(0,0), null, null, 0)); panel.doLayout(); final Dimension preferredSize = panel.getPreferredSize(); // after getPreferredSize() invocation, the field should be not null final DimensionInfo horizontalInfo = layoutManager.myHorizontalInfo; assertEquals(3, horizontalInfo.getCellCount()); assertEquals(GridConstraints.SIZEPOLICY_CAN_SHRINK, horizontalInfo.getCellSizePolicy(0)); assertEquals(GridConstraints.SIZEPOLICY_WANT_GROW, horizontalInfo.getCellSizePolicy(1)); assertEquals(GridConstraints.SIZEPOLICY_CAN_SHRINK, horizontalInfo.getCellSizePolicy(2)); assertEquals(100, preferredSize.width); assertEquals(60, preferredSize.height); panel.setSize(400, 100); panel.doLayout(); assertEquals(400, field1.getWidth()); assertEquals(400, field2.getWidth()); }