aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Alexander Zvegintsev <azvegint@openjdk.org> 2021-04-16 14:32:12 +0000
committerGravatar Alexander Zvegintsev <azvegint@openjdk.org> 2021-04-16 14:32:12 +0000
commit6946d91d7c3e6c07849894fc6934f3dc850ad9e9 (patch)
tree8f49b1eed7c720e55893fd65e2fd93508a36b758
parent714298a58ebb84dcf8f8cb4ae9c3a8ae649f6b47 (diff)
downloadjdk-6946d91d7c3e6c07849894fc6934f3dc850ad9e9.tar.gz
jdk-6946d91d7c3e6c07849894fc6934f3dc850ad9e9.zip
8075915: The eight controls without black backgrounds with WinLAF & GTK LAF & Nimbus LAF
Reviewed-by: psadhukhan, kizune, aivanov
-rw-r--r--test/jdk/javax/swing/JCheckBox/4449413/bug4449413.html40
-rw-r--r--test/jdk/javax/swing/JCheckBox/4449413/bug4449413.java215
2 files changed, 149 insertions, 106 deletions
diff --git a/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.html b/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.html
deleted file mode 100644
index aeed90ac79d..00000000000
--- a/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.html
+++ /dev/null
@@ -1,40 +0,0 @@
-<!--
- Copyright (c) 2012, 2013, 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.
--->
-
-<html>
-<body>
-When the applet starts, you'll see eight controls with black backgrounds.
-Four enabled (on the left side) and four disabled (on the right side)
-checkboxes and radiobuttons.
-
-1. If at least one of the controls' check marks is not visible:
- the test fails.
-
-2. Uncheck the "Use Ocean Theme" check box.
- If now at least one of the controls' check marks is not visible:
- the test fails.
-
-<applet code="bug4449413.class" width=250 height=190></applet>
-
-</body>
-</html>
diff --git a/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.java b/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.java
index 45ee7f56396..1efcfe58a31 100644
--- a/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.java
+++ b/test/jdk/javax/swing/JCheckBox/4449413/bug4449413.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2021, 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
@@ -25,87 +25,170 @@
* @bug 4449413
* @summary Tests that checkbox and radiobuttons' check marks are visible when background is black
* @author Ilya Boyandin
- * @library /test/lib
- * @modules java.desktop/sun.awt
- * @build jdk.test.lib.Platform
- * @run applet/manual=yesno bug4449413.html
+ * @run main/manual bug4449413
*/
-import javax.swing.*;
-import javax.swing.plaf.metal.*;
-import java.awt.event.*;
-import java.awt.*;
+import javax.swing.AbstractButton;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
+import javax.swing.UIManager;
+import javax.swing.plaf.metal.DefaultMetalTheme;
+import javax.swing.plaf.metal.MetalLookAndFeel;
+import javax.swing.plaf.metal.MetalTheme;
+import javax.swing.plaf.metal.OceanTheme;
+import java.awt.Color;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class bug4449413 extends JFrame {
+
+ private static final String INSTRUCTIONS =
+ "There are eight controls with black backgrounds.\n" +
+ "Four enabled (on the left side) and four disabled (on the right side)\n" +
+ "checkboxes and radiobuttons.\n\n" +
+ "1. If at least one of the controls' check marks is not visible:\n" +
+ " the test fails.\n";
+
+ private static final String INSTRUCTIONS_ADDITIONS_METAL =
+ "\n" +
+ "2. Uncheck the \"Use Ocean Theme\" check box.\n" +
+ " If now at least one of the controls' check marks is not visible:\n" +
+ " the test fails.\n";
+
+ private static final CountDownLatch latch = new CountDownLatch(1);
+ private static volatile boolean failed = true;
+
+ private final MetalTheme defaultMetalTheme = new DefaultMetalTheme();
+ private final MetalTheme oceanTheme = new OceanTheme();
+
+ private static bug4449413 instance;
+
+ boolean isMetalLookAndFeel() {
+ return UIManager.getLookAndFeel() instanceof MetalLookAndFeel;
+ }
+
+ public static void main(String[] args) throws Exception {
+ SwingUtilities.invokeLater(() -> {
+ instance = new bug4449413();
+ instance.createAndShowGUI();
+ });
-import jdk.test.lib.Platform;
+ boolean timeoutHappened = !latch.await(2, TimeUnit.MINUTES);
+
+ SwingUtilities.invokeAndWait(() -> {
+ if (instance != null) {
+ instance.dispose();
+ }
+ });
-public class bug4449413 extends JApplet {
+ System.out.println("Passed: " + !failed);
+
+ if (timeoutHappened || failed) {
+ throw new RuntimeException("Test failed!");
+ }
+ }
- @Override
- public void init() {
+ private void createAndShowGUI() {
+ setTitle(UIManager.getLookAndFeel().getClass().getName());
- try {
+ addComponentsToPane();
- if (Platform.isOSX()) {
- UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ latch.countDown();
}
+ });
+
+ setLocationRelativeTo(null);
+ pack();
+ setVisible(true);
+ }
+
+ public void addComponentsToPane() {
+ setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
+
+ JPanel testedPanel = new JPanel();
+ testedPanel.setLayout(new GridLayout(4, 6, 10, 15));
+ for (int k = 0; k <= 3; k++) {
+ for (int j = 1; j >= 0; j--) {
+ AbstractButton b = createButton(j, k);
+ testedPanel.add(b);
+ }
+ }
- final MetalTheme oceanTheme = (MetalTheme) sun.awt.AppContext.getAppContext().get("currentMetalTheme");
-
-
- SwingUtilities.invokeAndWait(new Runnable() {
-
- @Override
- public void run() {
- getContentPane().setLayout(new FlowLayout());
- final JPanel panel = new JPanel();
-
- JCheckBox box = new JCheckBox("Use Ocean theme", true);
- getContentPane().add(box);
- box.addItemListener(new ItemListener() {
-
- @Override
- public void itemStateChanged(ItemEvent e) {
- if (e.getStateChange() == ItemEvent.SELECTED) {
- MetalLookAndFeel.setCurrentTheme(oceanTheme);
- } else {
- MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
- }
- SwingUtilities.updateComponentTreeUI(panel);
- }
- });
-
- getContentPane().add(panel);
- panel.setLayout(new GridLayout(4, 6, 10, 15));
- for (int k = 0; k <= 3; k++) {
- for (int j = 1; j >= 0; j--) {
- AbstractButton b = createButton(j, k);
- panel.add(b);
- }
- }
+ add(testedPanel);
+
+
+ if (isMetalLookAndFeel()) {
+ JCheckBox oceanThemeSwitch = new JCheckBox("Use Ocean theme", true);
+ oceanThemeSwitch.addItemListener(e -> {
+ if (e.getStateChange() == ItemEvent.SELECTED) {
+ MetalLookAndFeel.setCurrentTheme(oceanTheme);
+ } else {
+ MetalLookAndFeel.setCurrentTheme(defaultMetalTheme);
}
+ SwingUtilities.updateComponentTreeUI(testedPanel);
});
- } catch (Exception e) {
- throw new RuntimeException(e);
+ add(oceanThemeSwitch);
}
+
+ JTextArea instructionArea = new JTextArea(
+ isMetalLookAndFeel()
+ ? INSTRUCTIONS + INSTRUCTIONS_ADDITIONS_METAL
+ : INSTRUCTIONS
+ );
+
+ instructionArea.setEditable(false);
+ instructionArea.setFocusable(false);
+ instructionArea.setMargin(new Insets(10,10,10,10));
+
+ add(instructionArea);
+
+
+ JButton passButton = new JButton("Pass");
+ JButton failButton = new JButton("Fail");
+
+ ActionListener actionListener = e -> {
+ failed = e.getSource() == failButton;
+ latch.countDown();
+ };
+
+ passButton.addActionListener(actionListener);
+ failButton.addActionListener(actionListener);
+
+ JPanel passFailPanel = new JPanel();
+ passFailPanel.add(passButton);
+ passFailPanel.add(failButton);
+
+ add(passFailPanel);
}
static AbstractButton createButton(int enabled, int type) {
- AbstractButton b = null;
- switch (type) {
- case 0:
- b = new JRadioButton("RadioButton");
- break;
- case 1:
- b = new JCheckBox("CheckBox");
- break;
- case 2:
- b = new JRadioButtonMenuItem("RBMenuItem");
- break;
- case 3:
- b = new JCheckBoxMenuItem("CBMenuItem");
- break;
- }
+ AbstractButton b = switch (type) {
+ case 0 -> new JRadioButton("RadioButton");
+ case 1 -> new JCheckBox("CheckBox");
+ case 2 -> new JRadioButtonMenuItem("RBMenuItem");
+ case 3 -> new JCheckBoxMenuItem("CBMenuItem");
+ default -> throw new IllegalArgumentException("type should be in range of 0..3");
+ };
+
+ b.setOpaque(true);
b.setBackground(Color.black);
b.setForeground(Color.white);
b.setEnabled(enabled == 1);