Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JSpinner/4973721/bug4973721.java
38853 views
/*1* Copyright (c) 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*/22/* @test23@bug 497372124@summary Up and Down Arrow key buttons are not working for the JSpinner in Synth LAF25@library ../../regtesthelpers26@build Util27@author Oleg Mokhovikov28@run main bug497372129*/3031import java.awt.Robot;32import javax.swing.event.ChangeListener;33import javax.swing.event.ChangeEvent;34import java.awt.event.KeyEvent;35import java.awt.event.FocusListener;36import java.awt.event.FocusEvent;37import javax.swing.*;3839public class bug4973721 implements ChangeListener, FocusListener {40static volatile boolean bStateChanged = false;41static volatile boolean bFocusGained = false;42static JSpinner spinner;43static final Object listener = new bug4973721();4445public void focusLost(FocusEvent e) {}4647public synchronized void focusGained(FocusEvent e) {48System.out.println("focusGained");49bFocusGained = true;50notifyAll();51}5253public synchronized void stateChanged(ChangeEvent e) {54System.out.println("stateChanged");55bStateChanged = true;56notifyAll();57}5859public static void main(String[] args) throws Exception {60UIManager.setLookAndFeel("javax.swing.plaf.synth.SynthLookAndFeel");6162SwingUtilities.invokeAndWait(new Runnable() {63public void run() {64final JFrame frame = new JFrame();65spinner = new JSpinner();66frame.getContentPane().add(spinner);67frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);6869frame.pack();70frame.setVisible(true);71spinner.addChangeListener((ChangeListener)listener);72spinner.addFocusListener((FocusListener)listener);73spinner.requestFocus();7475}76});7778synchronized(listener) {79if (!bFocusGained) {80System.out.println("waiting focusGained...");81try { listener.wait(5000); } catch (InterruptedException e) {}82}83}8485boolean hasFocus = Util.invokeOnEDT(new java.util.concurrent.Callable<Boolean>() {86@Override87public Boolean call() throws Exception {88return spinner.hasFocus();89}90});9192if (!bFocusGained && !hasFocus) {93throw new RuntimeException("Couldn't request focus for spinner");94}95Robot robot = new Robot();96robot.setAutoDelay(50);9798Util.hitKeys(robot, KeyEvent.VK_UP);99robot.waitForIdle();100Thread.sleep(1000);101102if (!bStateChanged) {103throw new RuntimeException("Up arrow key button doesn't work for a spinner in Synth L&F");104}105106bStateChanged = false;107108Util.hitKeys(robot, KeyEvent.VK_DOWN);109robot.waitForIdle();110Thread.sleep(1000);111112if (!bStateChanged) {113throw new RuntimeException("Down arrow key button doesn't work for a spinner in Synth L&F");114}115}116}117118119