From fc4eda05d9e2c749784fbbf1622a9fb1162308e5 Mon Sep 17 00:00:00 2001 From: duke Date: Fri, 27 Dec 2024 11:32:20 +0000 Subject: [PATCH] Backport d2d7d9a8b7c68865553dcbb4d660bbb06fde3974 --- .../javax/swing/JScrollPane/bug4688907.java | 44 +++++++++ .../javax/swing/SpringLayout/bug4756178.java | 93 +++++++++++++++++++ .../javax/swing/SpringLayout/bug4803649.java | 91 ++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 test/jdk/javax/swing/JScrollPane/bug4688907.java create mode 100644 test/jdk/javax/swing/SpringLayout/bug4756178.java create mode 100644 test/jdk/javax/swing/SpringLayout/bug4803649.java diff --git a/test/jdk/javax/swing/JScrollPane/bug4688907.java b/test/jdk/javax/swing/JScrollPane/bug4688907.java new file mode 100644 index 00000000000..4920a3bceee --- /dev/null +++ b/test/jdk/javax/swing/JScrollPane/bug4688907.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4688907 + * @summary ScrollPaneLayout.minimumLayoutSize incorrectly compares hsbPolicy + */ + +import java.awt.Dimension; +import javax.swing.JScrollPane; + +public class bug4688907 { + public static void main(String[] args) throws Exception { + JScrollPane sp = new JScrollPane(); + Dimension d1 = sp.getMinimumSize(); + sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + Dimension d2 = sp.getMinimumSize(); + if (d1.height == d2.height) { + throw new RuntimeException("The scrollbar minimum size doesn't take " + + "into account horizontal scrollbar policy"); + } + } +} diff --git a/test/jdk/javax/swing/SpringLayout/bug4756178.java b/test/jdk/javax/swing/SpringLayout/bug4756178.java new file mode 100644 index 00000000000..037d7683a4a --- /dev/null +++ b/test/jdk/javax/swing/SpringLayout/bug4756178.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4756178 + * @summary SpringLayout:applyDefaults() discards size information when right-aligning. + * @key headful + */ + +import java.awt.Dimension; +import java.awt.Robot; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.Spring; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; + +public class bug4756178 { + static JFrame fr; + static JButton bt; + static volatile Dimension buttonPreferredSize; + static volatile Dimension actualSize; + + public static void main(String[] args) throws Exception { + try { + SwingUtilities.invokeAndWait(() -> { + fr = new JFrame("bug4756178"); + JPanel p = (JPanel) fr.getContentPane(); + SpringLayout layout = new SpringLayout(); + p.setLayout(layout); + + SpringLayout.Constraints cc = new SpringLayout.Constraints(); + cc.setConstraint("East", + Spring.sum(Spring.constant(-20), + layout.getConstraint("East", p))); + cc.setConstraint("South", + Spring.sum(Spring.constant(-20), + layout.getConstraint("South", p))); + + bt = new JButton(); + + buttonPreferredSize = new Dimension(20, 20); + bt.setPreferredSize(buttonPreferredSize); + p.add(bt, cc); + + fr.setSize(200, 200); + fr.setLocationRelativeTo(null); + fr.setVisible(true); + }); + + Robot robot = new Robot(); + robot.waitForIdle(); + robot.delay(1000); + + SwingUtilities.invokeAndWait(() -> { + actualSize = bt.getSize(); + }); + + if (!buttonPreferredSize.equals(actualSize)) { + throw new RuntimeException("Button size is " + actualSize + + ", should be " + buttonPreferredSize); + } + } finally { + SwingUtilities.invokeAndWait(() -> { + if (fr != null) { + fr.dispose(); + } + }); + } + } +} diff --git a/test/jdk/javax/swing/SpringLayout/bug4803649.java b/test/jdk/javax/swing/SpringLayout/bug4803649.java new file mode 100644 index 00000000000..8b3c08548e8 --- /dev/null +++ b/test/jdk/javax/swing/SpringLayout/bug4803649.java @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4803649 + * @summary setWidth() doesn't work on the container in a SpringLayout + * @key headful + */ + +import java.awt.Dimension; +import java.awt.Robot; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.Spring; +import javax.swing.SpringLayout; +import javax.swing.SwingUtilities; + +public class bug4803649 { + static JFrame fr; + static JPanel panel; + + public static void main(String[] args) throws Exception { + try { + SwingUtilities.invokeAndWait(() -> { + fr = new JFrame("bug4803649"); + + panel = new JPanel(); + SpringLayout layout = new SpringLayout(); + panel.setLayout(layout); + + JTextArea textArea = new JTextArea("asasddsa"); + textArea.setPreferredSize(new Dimension(200, 200)); + panel.add(textArea); + SpringLayout.Constraints cCons = layout.getConstraints(textArea); + cCons.setX(Spring.constant(10)); + cCons.setY(Spring.constant(10)); + + SpringLayout.Constraints pCons = layout.getConstraints(panel); + pCons.setWidth(Spring.sum(Spring.constant(10), + cCons.getConstraint("East"))); + pCons.setHeight(Spring.sum(Spring.constant(10), + cCons.getConstraint("South"))); + + fr.getContentPane().add(panel); + + fr.setLocationRelativeTo(null); + fr.pack(); + fr.setVisible(true); + }); + + Robot r = new Robot(); + r.waitForIdle(); + r.delay(1000); + + SwingUtilities.invokeAndWait(() -> { + Dimension d = panel.getSize(); + if (d.width < 220 || d.height < 220) { + throw new RuntimeException("JPanel with the SpringLayout is too small"); + } + }); + } finally { + SwingUtilities.invokeAndWait(() -> { + if (fr != null) { + fr.dispose(); + } + }); + } + } +}