Path: blob/master/test/jdk/javax/swing/JPopupMenu/6583251/bug6583251.java
41155 views
/*1* Copyright (c) 2011, 2019, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* @test27* @key headful28* @bug 6583251 821737729* @summary One more ClassCastException in Swing with TrayIcon30* @author Alexander Potochkin31* @run main bug658325132*/3334import javax.swing.*;35import java.awt.*;36import java.awt.event.MouseEvent;37import java.awt.image.BufferedImage;3839public class bug6583251 {40private static JFrame frame;41private static JPopupMenu menu;4243private static void createGui() {44frame = new JFrame();45frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4647JPanel panel = new JPanel();48menu = new JPopupMenu();49menu.add(new JMenuItem("item"));50panel.setComponentPopupMenu(menu);51frame.add(panel);5253frame.setSize(200, 200);54frame.setLocationRelativeTo(null);55frame.setVisible(true);56}5758public static void main(String[] args) throws Exception {59if (SystemTray.isSupported()) {60SwingUtilities.invokeAndWait(new Runnable() {61public void run() {62createGui();63}64});6566Robot robot = new Robot();67robot.waitForIdle();68menu.show(frame, 0, 0);69robot.waitForIdle();7071TrayIcon trayIcon = new TrayIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB));72MouseEvent ev = new MouseEvent(73new JButton(), MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, 0, 0, 1, false);74ev.setSource(trayIcon);75Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ev);7677SwingUtilities.invokeAndWait(new Runnable() {78public void run() {79frame.dispose();80}81});8283} else {84System.out.println("SystemTray not supported. " + "Skipping the test.");85}86}87}888990