Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTree/4908142/bug4908142.java
38853 views
/*1* Copyright (c) 2009, 2012, 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*/222324/*25* @test26* @bug 490814227* @summary JList doesn't handle search function appropriately28* @author Andrey Pikalev29* @library ../../regtesthelpers30* @build Util31* @run main bug490814232*/33import javax.swing.*;34import javax.swing.tree.*;35import java.awt.*;36import java.awt.event.*;37import java.util.concurrent.Callable;3839public class bug4908142 {4041private static JTree tree;4243public static void main(String[] args) throws Exception {4445Robot robot = new Robot();46robot.setAutoDelay(50);4748SwingUtilities.invokeAndWait(new Runnable() {4950public void run() {51createAndShowGUI();52}53});5455robot.waitForIdle();5657SwingUtilities.invokeAndWait(new Runnable() {5859public void run() {60tree.requestFocus();61tree.setSelectionRow(0);62}63});6465robot.waitForIdle();666768robot.keyPress(KeyEvent.VK_A);69robot.keyRelease(KeyEvent.VK_A);70robot.keyPress(KeyEvent.VK_A);71robot.keyRelease(KeyEvent.VK_A);72robot.keyPress(KeyEvent.VK_D);73robot.keyRelease(KeyEvent.VK_D);74robot.waitForIdle();757677String sel = Util.invokeOnEDT(new Callable<String>() {7879@Override80public String call() throws Exception {81return tree.getLastSelectedPathComponent().toString();82}83});8485if (!"aad".equals(sel)) {86throw new Error("The selected index should be \"aad\", but not " + sel);87}88}8990private static void createAndShowGUI() {91JFrame fr = new JFrame("Test");92fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);9394String[] data = {"aaa", "aab", "aac", "aad", "ade", "bba"};95final DefaultMutableTreeNode root = new DefaultMutableTreeNode(data[0]);96for (int i = 1; i < data.length; i++) {97DefaultMutableTreeNode node = new DefaultMutableTreeNode(data[i]);98root.add(node);99}100101tree = new JTree(root);102103JScrollPane sp = new JScrollPane(tree);104fr.getContentPane().add(sp);105fr.setSize(200, 200);106fr.setVisible(true);107}108}109110111