Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JRadioButton/8075609/bug8075609.java
38853 views
/*1* Copyright (c) 2015, 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* @library ../../regtesthelpers26* @build Util27* @bug 807560928* @summary IllegalArgumentException when transferring focus from JRadioButton using tab29* @author Vivi An30* @run main bug807560931*/3233import javax.swing.*;34import javax.swing.event.*;35import java.awt.event.*;36import java.awt.*;37import sun.awt.SunToolkit;3839public class bug8075609 {40private static Robot robot;41private static SunToolkit toolkit;42private static JTextField textField;4344public static void main(String args[]) throws Throwable {45SwingUtilities.invokeAndWait(new Runnable() {46public void run() {47createAndShowGUI();48}49});5051robot = new Robot();52Thread.sleep(100);5354robot.setAutoDelay(100);55toolkit = (SunToolkit) Toolkit.getDefaultToolkit();5657// Radio button group tab key test58runTest1();59}6061private static void createAndShowGUI() {62JFrame mainFrame = new JFrame("Bug 8075609 - 1 test");6364JPanel rootPanel = new JPanel();65rootPanel.setLayout(new BorderLayout());6667JPanel formPanel = new JPanel();68formPanel.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());69formPanel.setFocusCycleRoot(true);7071JRadioButton option1 = new JRadioButton("Option 1", true);72JRadioButton option2 = new JRadioButton("Option 2");7374ButtonGroup radioButtonGroup = new ButtonGroup();75radioButtonGroup.add(option1);76radioButtonGroup.add(option2);7778formPanel.add(option1);79formPanel.add(option2);80textField = new JTextField("Another focusable component");81formPanel.add(textField);8283rootPanel.add(formPanel, BorderLayout.CENTER);8485JButton okButton = new JButton("OK");86rootPanel.add(okButton, BorderLayout.SOUTH);8788mainFrame.add(rootPanel);89mainFrame.pack();90mainFrame.setVisible(true);91mainFrame.toFront();92}9394// Radio button Group as a single component when traversing through tab key95private static void runTest1() throws Exception{96hitKey(robot, KeyEvent.VK_TAB);9798robot.setAutoDelay(1000 );99SwingUtilities.invokeAndWait(new Runnable() {100public void run() {101if (textField.hasFocus()) {102System.out.println("Radio Button Group Go To Next Component through Tab Key failed");103throw new RuntimeException("Focus is not on textField as Expected");104}105}106});107}108109private static void hitKey(Robot robot, int keycode) {110robot.keyPress(keycode);111robot.keyRelease(keycode);112toolkit.realSync();113}114}115116117