Skip to content

Commit b01a15e

Browse files
skodandaaivanov-jdk
authored andcommitted
8258884: [TEST_BUG] Convert applet-based test open/test/jdk/javax/swing/JMenuItem/8031573/bug8031573.java to a regular java test
Reviewed-by: aivanov, serb
1 parent 6d4a593 commit b01a15e

File tree

2 files changed

+86
-62
lines changed

2 files changed

+86
-62
lines changed

test/jdk/javax/swing/JMenuItem/8031573/bug8031573.html

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 86 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -20,45 +20,109 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
24+
import java.awt.BorderLayout;
2325
import java.awt.FlowLayout;
24-
import javax.swing.JApplet;
26+
import java.awt.event.WindowAdapter;
27+
import java.awt.event.WindowEvent;
28+
import java.util.concurrent.CountDownLatch;
29+
import java.util.concurrent.TimeUnit;
30+
import javax.swing.JButton;
2531
import javax.swing.JCheckBoxMenuItem;
32+
import javax.swing.JFrame;
2633
import javax.swing.JMenu;
2734
import javax.swing.JMenuBar;
35+
import javax.swing.JMenuItem;
36+
import javax.swing.JPanel;
37+
import javax.swing.JTextArea;
38+
import javax.swing.JTextField;
2839
import javax.swing.SwingUtilities;
2940
import javax.swing.UIManager;
41+
import javax.swing.text.JTextComponent;
3042

3143
/* @test
3244
* @bug 8031573 8040279 8143064
3345
* @summary [macosx] Checkmarks of JCheckBoxMenuItems aren't rendered
3446
* in high resolution on Retina
35-
* @author Alexander Scherbatiy
36-
* @run applet/manual=yesno bug8031573.html
47+
* @run main/manual bug8031573
3748
*/
38-
public class bug8031573 extends JApplet {
3949

40-
@Override
41-
public void init() {
42-
try {
50+
public class bug8031573 {
51+
52+
private static volatile JFrame frame;
53+
private static volatile boolean passed = false;
54+
private static final CountDownLatch latch = new CountDownLatch(1);
4355

44-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
56+
public static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n"
57+
+ "Verify that high resolution system icons are used for JCheckBoxMenuItem on HiDPI displays.\n"
58+
+ "If the display does not support HiDPI mode press PASS.\n"
59+
+ "1. Run the test on HiDPI Display.\n"
60+
+ "2. Open the Menu.\n"
61+
+ "3. Check that the icon on the JCheckBoxMenuItem is smooth.\n"
62+
+ " If so, press PASS, else press FAIL.\n";
4563

46-
SwingUtilities.invokeAndWait(new Runnable() {
64+
public static void main(String args[]) throws Exception {
65+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
66+
try {
67+
SwingUtilities.invokeAndWait(() -> createTestGUI());
4768

48-
@Override
49-
public void run() {
50-
JMenuBar bar = new JMenuBar();
51-
JMenu menu = new JMenu("Menu");
52-
JCheckBoxMenuItem checkBoxMenuItem
53-
= new JCheckBoxMenuItem("JCheckBoxMenuItem");
54-
checkBoxMenuItem.setSelected(true);
55-
menu.add(checkBoxMenuItem);
56-
bar.add(menu);
57-
setJMenuBar(bar);
69+
if (!latch.await(5, TimeUnit.MINUTES)) {
70+
throw new RuntimeException("Test has timed out!");
71+
}
72+
if (!passed) {
73+
throw new RuntimeException("Test failed!");
74+
}
75+
} finally {
76+
SwingUtilities.invokeAndWait(() -> {
77+
if (frame != null) {
78+
frame.dispose();
5879
}
5980
});
60-
} catch (Exception e) {
61-
throw new RuntimeException(e);
6281
}
6382
}
83+
84+
private static void createTestGUI() {
85+
frame = new JFrame("bug8031573");
86+
JMenuBar bar = new JMenuBar();
87+
JMenu menu = new JMenu("Menu");
88+
JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem("JCheckBoxMenuItem");
89+
checkBoxMenuItem.setSelected(true);
90+
menu.add(checkBoxMenuItem);
91+
bar.add(menu);
92+
frame.setJMenuBar(bar);
93+
94+
JPanel panel = new JPanel(new BorderLayout());
95+
JTextComponent textComponent = new JTextArea(INSTRUCTIONS);
96+
textComponent.setEditable(false);
97+
panel.add(textComponent, BorderLayout.CENTER);
98+
99+
JPanel buttonsPanel = new JPanel(new FlowLayout());
100+
JButton passButton = new JButton("Pass");
101+
passButton.addActionListener((e) -> {
102+
System.out.println("Test passed!");
103+
passed = true;
104+
latch.countDown();
105+
});
106+
JButton failsButton = new JButton("Fail");
107+
failsButton.addActionListener((e) -> {
108+
passed = false;
109+
latch.countDown();
110+
});
111+
112+
buttonsPanel.add(passButton);
113+
buttonsPanel.add(failsButton);
114+
panel.add(buttonsPanel, BorderLayout.SOUTH);
115+
116+
frame.getContentPane().add(panel);
117+
118+
frame.addWindowListener(new WindowAdapter() {
119+
@Override
120+
public void windowClosing(WindowEvent e) {
121+
latch.countDown();
122+
}
123+
});
124+
frame.pack();
125+
frame.setLocationRelativeTo(null);
126+
frame.setVisible(true);
127+
}
64128
}

0 commit comments

Comments
 (0)