Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/PopupFactory/6276087/NonOpaquePopupMenuTest.java
38918 views
/*1* Copyright (c) 2011, 2013, 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*/2223/**24* @test25* @bug 627608726* @author Romain Guy27* @summary Tests opacity of a popup menu.28*/29import java.awt.*;30import java.awt.event.*;3132import javax.swing.*;3334public class NonOpaquePopupMenuTest extends JFrame {3536private static JMenu fileMenu;3738public NonOpaquePopupMenuTest() {39getContentPane().setBackground(java.awt.Color.RED);40JMenuBar menuBar = new JMenuBar();41fileMenu = new JMenu("File");42JMenuItem menuItem = new JMenuItem("New");43menuBar.add(fileMenu);44setJMenuBar(menuBar);4546fileMenu.add(menuItem);47fileMenu.getPopupMenu().setOpaque(false);4849setSize(new Dimension(640, 480));50setVisible(true);51}5253public static void main(String[] args) throws Throwable {54Robot robot = new Robot();55robot.setAutoDelay(250);5657SwingUtilities.invokeAndWait(new Runnable() {5859@Override60public void run() {61new NonOpaquePopupMenuTest();62}63});6465robot.waitForIdle();6667Point p = getMenuClickPoint();68robot.mouseMove(p.x, p.y);69robot.mousePress(InputEvent.BUTTON1_MASK);70robot.mouseRelease(InputEvent.BUTTON1_MASK);7172robot.waitForIdle();7374if (isParentOpaque()) {75throw new RuntimeException("Popup menu parent is opaque");76}7778}7980private static boolean isParentOpaque() throws Exception {81final boolean result[] = new boolean[1];8283SwingUtilities.invokeAndWait(new Runnable() {8485@Override86public void run() {87result[0] = fileMenu.getPopupMenu().getParent().isOpaque();88}89});9091return result[0];92}9394private static Point getMenuClickPoint() throws Exception {95final Point[] result = new Point[1];9697SwingUtilities.invokeAndWait(new Runnable() {9899@Override100public void run() {101Point p = fileMenu.getLocationOnScreen();102Dimension size = fileMenu.getSize();103104result[0] = new Point(p.x + size.width / 2,105p.y + size.height / 2);106}107});108109return result[0];110111}112}113114115