Path: blob/master/test/jdk/javax/swing/DefaultButtonModel/DefaultButtonModelCrashTest.java
41149 views
/*1* Copyright (c) 2017, 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* @bug 818257726* @summary Verifies if moving focus via custom ButtonModel causes crash27* @key headful28* @run main DefaultButtonModelCrashTest29*/3031import java.awt.BorderLayout;32import java.awt.Container;33import java.awt.Point;34import java.awt.Robot;35import java.awt.event.KeyEvent;36import javax.swing.ButtonModel;37import javax.swing.DefaultButtonModel;38import javax.swing.JCheckBox;39import javax.swing.JComponent;40import javax.swing.JFrame;41import javax.swing.JPanel;42import javax.swing.JTextField;43import javax.swing.SwingUtilities;4445public class DefaultButtonModelCrashTest {46private JFrame frame = null;47private JPanel panel;48private volatile Point p = null;4950public static void main(String[] args) throws Exception {51new DefaultButtonModelCrashTest();52}5354public DefaultButtonModelCrashTest() throws Exception {55try {56Robot robot = new Robot();57robot.setAutoDelay(200);58SwingUtilities.invokeAndWait(() -> go());59robot.waitForIdle();60robot.keyPress(KeyEvent.VK_TAB);61robot.keyRelease(KeyEvent.VK_TAB);62robot.delay(100);63robot.keyPress(KeyEvent.VK_TAB);64robot.keyRelease(KeyEvent.VK_TAB);65} finally {66if (frame != null) { SwingUtilities.invokeAndWait(()->frame.dispose()); }67}68}6970private void go() {7172frame = new JFrame();73frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);74Container contentPane = frame.getContentPane();75ButtonModel model = new DefaultButtonModel();7677JCheckBox check = new JCheckBox("a bit broken");78check.setModel(model);79panel = new JPanel(new BorderLayout());80panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH);81panel.add(check);82contentPane.add(panel);83frame.setLocationRelativeTo(null);84frame.pack();85frame.setVisible(true);86}87}888990