Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTree/6578666/bug6578666.java
38853 views
/*1* Copyright (c) 2011, 2014, 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/*23* @test24* @bug 657866625* @summary REGRESSION: Exception occurs when updateUI for JTree is triggered by KeyEvent26* @run main bug657866627* @author Alexander Potochkin28*/2930import javax.swing.*;31import java.awt.*;32import java.awt.event.KeyAdapter;33import java.awt.event.KeyEvent;3435public class bug6578666 {3637private static JTree tree;3839private static void createGui() {40final JFrame frame = new JFrame();41frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);4243tree = new JTree();44frame.add(tree);4546tree.addKeyListener(new KeyAdapter() {47public void keyPressed(KeyEvent e) {48tree.updateUI();49}50});5152frame.setSize(200, 200);53frame.setLocationRelativeTo(null);54frame.setVisible(true);55}5657public static void main(String[] args) throws Exception {58Robot robot = new Robot();59robot.setAutoDelay(10);6061SwingUtilities.invokeAndWait(new Runnable() {62public void run() {63bug6578666.createGui();64}65});6667robot.waitForIdle();6869tree.requestFocus();70robot.waitForIdle();7172robot.keyPress(KeyEvent.VK_SPACE);73robot.keyRelease(KeyEvent.VK_SPACE);74robot.waitForIdle();75robot.keyPress(KeyEvent.VK_SPACE);76robot.keyRelease(KeyEvent.VK_SPACE);7778}79}808182