void () { final JPanel panel = new JPanel(new GridBagLayout()); final JLabel label1 = new JLabel(); label1.setPreferredSize(new Dimension(15,20)); final JLabel label2 = new JLabel(); label2.setPreferredSize(new Dimension(15,20)); final JTextArea textArea = new JTextArea(); textArea.setLineWrap(true); GridBagConverter converter = new GridBagConverter(); converter.addComponent(label1, new GridConstraints(0,0,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); converter.addComponent(label2, new GridConstraints(0,1,1,1,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0)); converter.addComponent(textArea, new GridConstraints(1,0,1,2,GridConstraints.ANCHOR_CENTER,GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0)); applyConversionResults(panel, converter); int textAreaWidth = JavaVersion.current().feature >= 9 ? 101 : 100; assertEquals(textAreaWidth, textArea.getPreferredSize().width); final Dimension initialPreferredSize = panel.getPreferredSize(); assertEquals(new Dimension(textAreaWidth, 20 + textArea.getPreferredSize().height), initialPreferredSize); panel.setSize(initialPreferredSize); panel.invalidate(); panel.doLayout(); assertEquals(initialPreferredSize, panel.getPreferredSize()); }