Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JLabel/6596966/bug6596966.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/* @test24@bug 659696625@summary Some JFileChooser mnemonics do not work with sticky keys26@library ../../regtesthelpers27@library ../../../../lib/testlibrary28@build Util jdk.testlibrary.OSInfo29@run main bug659696630@author Pavel Porvatov31*/3233import java.awt.*;34import java.awt.event.KeyEvent;35import java.awt.event.InputEvent;36import java.util.ArrayList;37import javax.swing.*;3839import jdk.testlibrary.OSInfo;4041public class bug6596966 {42private static JFrame frame;4344private static JLabel label;45private static JButton button;46private static JComboBox comboBox;4748public static void main(String[] args) throws Exception {49Robot robot = new Robot();5051SwingUtilities.invokeAndWait(new Runnable() {52public void run() {53button = new JButton("Button");54comboBox = new JComboBox();5556label = new JLabel("Label");57label.setDisplayedMnemonic('L');58label.setLabelFor(comboBox);5960JPanel pnContent = new JPanel();6162pnContent.add(button);63pnContent.add(label);64pnContent.add(comboBox);6566frame = new JFrame();6768frame.add(pnContent);69frame.pack();70frame.setVisible(true);71}72});7374robot.waitForIdle();757677int keyMask = InputEvent.ALT_MASK;78if (OSInfo.getOSType() == OSInfo.OSType.MACOSX) {79keyMask = InputEvent.CTRL_MASK | InputEvent.ALT_MASK;80}81ArrayList<Integer> keys = Util.getKeyCodesFromKeyMask(keyMask);82for (int i = 0; i < keys.size(); ++i) {83robot.keyPress(keys.get(i));84}8586robot.keyPress(KeyEvent.VK_L);8788robot.waitForIdle();89Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new KeyEvent(label, KeyEvent.KEY_RELEASED,90EventQueue.getMostRecentEventTime(), 0, KeyEvent.VK_L, 'L'));9192robot.waitForIdle();9394try {95SwingUtilities.invokeAndWait(new Runnable() {96public void run() {97if (!comboBox.isFocusOwner()) {98throw new RuntimeException("comboBox isn't focus owner");99}100}101});102} finally {103robot.keyRelease(KeyEvent.VK_L);104for (int i = 0; i < keys.size(); ++i) {105robot.keyRelease(keys.get(i));106}107robot.waitForIdle();108}109}110}111112113