Path: blob/master/test/jdk/javax/swing/JMenuItem/8031573/bug8031573.java
41153 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.BorderLayout;24import java.awt.FlowLayout;25import java.awt.event.WindowAdapter;26import java.awt.event.WindowEvent;27import java.util.concurrent.CountDownLatch;28import java.util.concurrent.TimeUnit;29import javax.swing.JButton;30import javax.swing.JCheckBoxMenuItem;31import javax.swing.JFrame;32import javax.swing.JMenu;33import javax.swing.JMenuBar;34import javax.swing.JMenuItem;35import javax.swing.JPanel;36import javax.swing.JTextArea;37import javax.swing.JTextField;38import javax.swing.SwingUtilities;39import javax.swing.UIManager;40import javax.swing.text.JTextComponent;4142/* @test43* @bug 8031573 8040279 814306444* @summary [macosx] Checkmarks of JCheckBoxMenuItems aren't rendered45* in high resolution on Retina46* @run main/manual bug803157347*/4849public class bug8031573 {5051private static volatile JFrame frame;52private static volatile boolean passed = false;53private static final CountDownLatch latch = new CountDownLatch(1);5455public static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n"56+ "Verify that high resolution system icons are used for JCheckBoxMenuItem on HiDPI displays.\n"57+ "If the display does not support HiDPI mode press PASS.\n"58+ "1. Run the test on HiDPI Display.\n"59+ "2. Open the Menu.\n"60+ "3. Check that the icon on the JCheckBoxMenuItem is smooth.\n"61+ " If so, press PASS, else press FAIL.\n";6263public static void main(String args[]) throws Exception {64UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());65try {66SwingUtilities.invokeAndWait(() -> createTestGUI());6768if (!latch.await(5, TimeUnit.MINUTES)) {69throw new RuntimeException("Test has timed out!");70}71if (!passed) {72throw new RuntimeException("Test failed!");73}74} finally {75SwingUtilities.invokeAndWait(() -> {76if (frame != null) {77frame.dispose();78}79});80}81}8283private static void createTestGUI() {84frame = new JFrame("bug8031573");85JMenuBar bar = new JMenuBar();86JMenu menu = new JMenu("Menu");87JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem("JCheckBoxMenuItem");88checkBoxMenuItem.setSelected(true);89menu.add(checkBoxMenuItem);90bar.add(menu);91frame.setJMenuBar(bar);9293JPanel panel = new JPanel(new BorderLayout());94JTextComponent textComponent = new JTextArea(INSTRUCTIONS);95textComponent.setEditable(false);96panel.add(textComponent, BorderLayout.CENTER);9798JPanel buttonsPanel = new JPanel(new FlowLayout());99JButton passButton = new JButton("Pass");100passButton.addActionListener((e) -> {101System.out.println("Test passed!");102passed = true;103latch.countDown();104});105JButton failsButton = new JButton("Fail");106failsButton.addActionListener((e) -> {107passed = false;108latch.countDown();109});110111buttonsPanel.add(passButton);112buttonsPanel.add(failsButton);113panel.add(buttonsPanel, BorderLayout.SOUTH);114115frame.getContentPane().add(panel);116117frame.addWindowListener(new WindowAdapter() {118@Override119public void windowClosing(WindowEvent e) {120latch.countDown();121}122});123frame.pack();124frame.setLocationRelativeTo(null);125frame.setVisible(true);126}127}128129130