--- /dev/null 2019-05-20 08:21:18.000000000 -0700 +++ new/test/jdk/javax/swing/JColorChooser/8153090/JColorChooserContainerFocus.java 2019-05-20 08:21:16.000000000 -0700 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* +* @test +* @bug 8153090 8223788 8224149 +* @summary 8153090: TAB key cannot change input focus after the radio button in +* the Color Selection dialog. +* 8223788: JSpinner buttons in JColorChooser dialog may capture focus +* using TAB Key. +* 8224149: JColorChoser doesn't update the color diagram when the +* selection is changed by keys. +* +* @run main JColorChooserContainerFocus +*/ + +import javax.swing.*; +import java.awt.*; +import java.awt.event.KeyEvent; + +public class JColorChooserContainerFocus { + static JFrame frame; + static JColorChooser cc; + static Robot robot; + static Color color; + static Point point; + static Color diagram; + + public static void main(String args[]) throws Exception { + + if( !(UIManager.getLookAndFeel().getName().equals("Metal") || + UIManager.getLookAndFeel().getName().equals("Mac OS X"))) { + return; + } + + SwingUtilities.invokeAndWait(() -> { + frame = new JFrame(); + cc = new JColorChooser(Color.WHITE); + frame.getContentPane().add(cc); + frame.pack(); + frame.setVisible(true); + }); + + robot = new Robot(); + robot.setAutoWaitForIdle(true); + robot.setAutoDelay(50); + + robot.waitForIdle(); + robot.delay(200); + + if (UIManager.getLookAndFeel().isNativeLookAndFeel()) { + robot.keyPress(KeyEvent.VK_SHIFT); + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_SHIFT); + } + + robot.keyPress(KeyEvent.VK_RIGHT); + robot.keyRelease(KeyEvent.VK_RIGHT); + + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + + robot.waitForIdle(); + robot.delay(200); + + SwingUtilities.invokeAndWait(() -> { + point = frame.getLocationOnScreen(); + point.translate(100, 100); + diagram = robot.getPixelColor(point.x, point.y); + }); + + robot.keyPress(KeyEvent.VK_DOWN); + robot.keyRelease(KeyEvent.VK_DOWN); + + robot.waitForIdle(); + robot.delay(200); + + SwingUtilities.invokeAndWait(() -> { + if (diagram.equals(robot.getPixelColor(point.x, point.y))) { + diagram = null; + } + }); + + if (diagram == null) { + throw new AssertionError("Diagram was not updated."); + } + + for (int i = 0; i < 6; i++) { + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + } + + robot.keyPress(KeyEvent.VK_1); + robot.keyRelease(KeyEvent.VK_1); + + robot.keyPress(KeyEvent.VK_0); + robot.keyRelease(KeyEvent.VK_0); + + robot.keyPress(KeyEvent.VK_0); + robot.keyRelease(KeyEvent.VK_0); + + robot.keyPress(KeyEvent.VK_TAB); + robot.keyRelease(KeyEvent.VK_TAB); + + SwingUtilities.invokeAndWait(() -> color = + cc.getSelectionModel().getSelectedColor()); + + SwingUtilities.invokeLater(frame::dispose); + + if (!Color.RED.equals(color)) { + throw new AssertionError("Test failed: the color should be red."); + } + + } +}