Skip to content

Commit

Permalink
8315882: Open some swing tests 2
Browse files Browse the repository at this point in the history
Reviewed-by: honkar, prr
  • Loading branch information
Alisen Chung committed Sep 23, 2023
1 parent 68a9c81 commit d2d7d9a
Show file tree
Hide file tree
Showing 3 changed files with 228 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/jdk/javax/swing/JScrollPane/bug4688907.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
93 changes: 93 additions & 0 deletions test/jdk/javax/swing/SpringLayout/bug4756178.java
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
}
}
91 changes: 91 additions & 0 deletions test/jdk/javax/swing/SpringLayout/bug4803649.java
Original file line number Diff line number Diff line change
@@ -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();
}
});
}
}
}

1 comment on commit d2d7d9a

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.