1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 /* 24 * @test 25 * @bug 8182577 26 * @summary Verifies if moving focus via custom ButtonModel causes crash 27 * @run main DefaultButtonModelCrashTest 28 */ 29 import java.awt.BorderLayout; 30 import java.awt.Container; 31 import java.awt.Point; 32 import java.awt.Robot; 33 import java.awt.event.KeyEvent; 34 import javax.swing.ButtonModel; 35 import javax.swing.DefaultButtonModel; 36 import javax.swing.JCheckBox; 37 import javax.swing.JComponent; 38 import javax.swing.JFrame; 39 import javax.swing.JPanel; 40 import javax.swing.JTextField; 41 import javax.swing.SwingUtilities; 42 43 public class DefaultButtonModelCrashTest { 44 private JFrame frame = null; 45 private JPanel panel; 46 private volatile Point p = null; 47 48 public static void main(String[] args) throws Exception { 49 new DefaultButtonModelCrashTest(); 50 } 51 52 public DefaultButtonModelCrashTest() throws Exception { 53 try { 54 Robot robot = new Robot(); 55 robot.setAutoDelay(200); 56 SwingUtilities.invokeAndWait(() -> go()); 57 robot.waitForIdle(); 58 robot.keyPress(KeyEvent.VK_TAB); 59 robot.keyRelease(KeyEvent.VK_TAB); 60 robot.delay(100); 61 robot.keyPress(KeyEvent.VK_TAB); 62 robot.keyRelease(KeyEvent.VK_TAB); 63 } finally { 64 SwingUtilities.invokeAndWait(()->frame .dispose()); 65 } 66 } 67 68 private void go() { 69 70 frame = new JFrame(); 71 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 72 Container contentPane = frame.getContentPane(); 73 ButtonModel model = new DefaultButtonModel(); 74 75 JCheckBox check = new JCheckBox("a bit broken"); 76 check.setModel(model); 77 panel = new JPanel(new BorderLayout()); 78 panel.add(new JTextField("Press Tab (twice?)"), BorderLayout.NORTH); 79 panel.add(check); 80 contentPane.add(panel); 81 frame.setLocationRelativeTo(null); 82 frame.pack(); 83 frame.setVisible(true); 84 } 85 }