From 3c153b870dac56ae113e1b8da1391c3beb4c0925 Mon Sep 17 00:00:00 2001 From: Patrick Ziegler Date: Mon, 6 Jul 2026 18:38:11 +0200 Subject: [PATCH] Evaluate `GridBagLayout.setConstraints()` #1539 This method may be used instead of `add(comp, constraints)` and must therefore be evaluated. Otherwise the constraints are not set at design time. Closes https://github.com/eclipse-windowbuilder/windowbuilder/issues/1539 --- .../wbp-meta/.wbp-cache-presentations | 2 +- .../java/awt/GridBagLayout.wbp-component.xml | 7 ++++ org.eclipse.wb.tests/META-INF/MANIFEST.MF | 2 +- org.eclipse.wb.tests/pom.xml | 2 +- .../layout/gbl/GridBagConstraintsTest.java | 33 +++++++++++++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/org.eclipse.wb.swing/wbp-meta/.wbp-cache-presentations b/org.eclipse.wb.swing/wbp-meta/.wbp-cache-presentations index 619ce95f41..1ec18b8e5d 100644 --- a/org.eclipse.wb.swing/wbp-meta/.wbp-cache-presentations +++ b/org.eclipse.wb.swing/wbp-meta/.wbp-cache-presentations @@ -1 +1 @@ -7879b7f1b9d6189960c278dcdaddeeae \ No newline at end of file +25ac5b3b39f8d6f8c3db96a940f0b80b \ No newline at end of file diff --git a/org.eclipse.wb.swing/wbp-meta/java/awt/GridBagLayout.wbp-component.xml b/org.eclipse.wb.swing/wbp-meta/java/awt/GridBagLayout.wbp-component.xml index 715b874fad..fa74c3132b 100644 --- a/org.eclipse.wb.swing/wbp-meta/java/awt/GridBagLayout.wbp-component.xml +++ b/org.eclipse.wb.swing/wbp-meta/java/awt/GridBagLayout.wbp-component.xml @@ -4,6 +4,13 @@ The GridBagLayout class is a flexible layout manager that aligns components vertically and horizontally, without requiring that the components be of the same size. Each GridBagLayout object maintains a dynamic, rectangular grid of cells, with each component occupying, one or more cells. + + + + + + + diff --git a/org.eclipse.wb.tests/META-INF/MANIFEST.MF b/org.eclipse.wb.tests/META-INF/MANIFEST.MF index c8a94ee8ce..aa51c08076 100644 --- a/org.eclipse.wb.tests/META-INF/MANIFEST.MF +++ b/org.eclipse.wb.tests/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: WindowBuilder Tests Bundle-SymbolicName: org.eclipse.wb.tests;singleton:=true -Bundle-Version: 1.7.300.qualifier +Bundle-Version: 1.8.0.qualifier Bundle-Activator: org.eclipse.wb.tests.designer.tests.Activator Bundle-Vendor: Google Bundle-RequiredExecutionEnvironment: JavaSE-21 diff --git a/org.eclipse.wb.tests/pom.xml b/org.eclipse.wb.tests/pom.xml index 655562f827..ef997c1e04 100644 --- a/org.eclipse.wb.tests/pom.xml +++ b/org.eclipse.wb.tests/pom.xml @@ -18,7 +18,7 @@ org.eclipse.wb org.eclipse.wb.tests - 1.7.300-SNAPSHOT + 1.8.0-SNAPSHOT eclipse-test-plugin diff --git a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagConstraintsTest.java b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagConstraintsTest.java index 182975aa8d..32dd29662b 100644 --- a/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagConstraintsTest.java +++ b/org.eclipse.wb.tests/src/org/eclipse/wb/tests/designer/swing/model/layout/gbl/GridBagConstraintsTest.java @@ -132,6 +132,39 @@ public Test() { assertSame(layout.getRows().get(0), constraints.getRow()); } + @Test + public void test_access1() throws Exception { + test_access("\t\tlayout.setConstraints(label, new GridBagConstraints(0, 0, 1, 1, 100, 100, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(10, 10, 0, 0), 5, 5));"); + } + + @Test + public void test_access2() throws Exception { + test_access(""" + \t\tGridBagConstraints constraints = new GridBagConstraints(0, 0, 1, 1, 100, 100, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(10, 10, 0, 0), 5, 5); + \t\tlayout.setConstraints(label, constraints); + """); + } + + private void test_access(String code) throws Exception { + ContainerInfo panel = parseContainer(""" + public class Test extends JPanel { + public Test() { + GridBagLayout layout = new GridBagLayout(); + setLayout(layout); + + JLabel label = new JLabel("New label"); + add(label); + + %s + } + }""".formatted(code)); + ContainerInfo label = panel.getChildren(ContainerInfo.class).getFirst(); + GridBagConstraintsInfo constraints = GridBagLayoutInfo.getConstraintsFor(label); + + assertEquals(constraints.getInsets("left"), 10); + assertEquals(constraints.getInsets("top"), 10); + } + @Test public void test_properties() throws Exception { ContainerInfo panel = parseContainer("""