From c51406a1cab66e9ac7710694c56b9fee13b6b352 Mon Sep 17 00:00:00 2001 From: Damon Nguyen Date: Sat, 23 Nov 2024 20:39:30 -0800 Subject: [PATCH 1/4] Initial commit for backout --- .../swing/plaf/basic/BasicScrollBarUI.java | 45 ----------- .../JComboBox/JComboBoxScrollFocusTest.java | 75 ------------------- 2 files changed, 120 deletions(-) delete mode 100644 test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java diff --git a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java index 9fc9b64314cb9..60274d766cd70 100644 --- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicScrollBarUI.java @@ -31,7 +31,6 @@ import java.awt.Dimension; import java.awt.Graphics; import java.awt.Insets; -import java.awt.KeyboardFocusManager; import java.awt.LayoutManager; import java.awt.Point; import java.awt.Rectangle; @@ -123,8 +122,6 @@ public class BasicScrollBarUI protected ArrowButtonListener buttonListener; /** Model listener */ protected ModelListener modelListener; - /** KeyboardFocusListener */ - protected KeyboardFocusListener keyboardFocusListener; /** Thumb rectangle */ protected Rectangle thumbRect; @@ -359,15 +356,12 @@ protected void installListeners(){ buttonListener = createArrowButtonListener(); modelListener = createModelListener(); propertyChangeListener = createPropertyChangeListener(); - keyboardFocusListener = createKeyboardFocusListener(); scrollbar.addMouseListener(trackListener); scrollbar.addMouseMotionListener(trackListener); scrollbar.getModel().addChangeListener(modelListener); scrollbar.addPropertyChangeListener(propertyChangeListener); scrollbar.addFocusListener(getHandler()); - KeyboardFocusManager.getCurrentKeyboardFocusManager() - .addPropertyChangeListener(keyboardFocusListener); if (incrButton != null) { incrButton.addMouseListener(buttonListener); @@ -449,8 +443,6 @@ protected void uninstallListeners() { incrButton.removeMouseListener(buttonListener); } - KeyboardFocusManager.getCurrentKeyboardFocusManager() - .removePropertyChangeListener(keyboardFocusListener); scrollbar.getModel().removeChangeListener(modelListener); scrollbar.removeMouseListener(trackListener); scrollbar.removeMouseMotionListener(trackListener); @@ -517,14 +509,6 @@ protected PropertyChangeListener createPropertyChangeListener() { return getHandler(); } - /** - * Creates a keyboard focus listener. - * @return a keyboard focus listener - */ - protected KeyboardFocusListener createKeyboardFocusListener() { - return new KeyboardFocusListener(); - } - private void updateThumbState(int x, int y) { Rectangle rect = getThumbBounds(); @@ -1218,35 +1202,6 @@ public boolean getSupportsAbsolutePositioning() { return supportsAbsolutePositioning; } - /** - * A listener to listen for keyboard focus changes. - */ - protected class KeyboardFocusListener implements PropertyChangeListener { - /** - * Constructs a {@code KeyboardFocusListener}. - */ - protected KeyboardFocusListener() {} - - @Override - public void propertyChange(PropertyChangeEvent e) { - String propertyName = e.getPropertyName(); - - if ("focusOwner" == propertyName) { - // Stop scrolling if no longer focus owner - if (e.getNewValue() == null && scrollTimer.isRunning()) { - scrollTimer.stop(); - buttonListener.handledEvent = false; - scrollbar.setValueIsAdjusting(false); - if (incrButton.getModel().isPressed()) { - incrButton.getModel().setPressed(false); - } else if (decrButton.getModel().isPressed()) { - decrButton.getModel().setPressed(false); - } - } - } - } - } - /** * A listener to listen for model changes. */ diff --git a/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java b/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java deleted file mode 100644 index 4d2c3bd19ccfe..0000000000000 --- a/test/jdk/javax/swing/JComboBox/JComboBoxScrollFocusTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -import javax.swing.JComboBox; -import javax.swing.JFrame; - -/* - * @test - * @bug 6672644 - * @library /java/awt/regtesthelpers - * @build PassFailJFrame - * @summary Tests JComboBox scrollbar behavior when alt-tabbing - * @requires os.family != "mac" - * @run main/manual JComboBoxScrollFocusTest - */ - -public class JComboBoxScrollFocusTest { - private static final String INSTRUCTIONS = - """ - Click on the dropdown button for the JComboBox in the test frame. - Then, press and hold the left click button on the down arrow button - in the popup list. While holding the left click button, the list - should be scrolling down. Press ALT + TAB while holding down the - left click to switch focus to a different window. Then release the - left click button. Focus the test frame again and click the - dropdown button for the JComboBox again. The list should be - stationary and not be automatically scrolling. - - If you are able to execute all steps successfully then the test - passes, otherwise it fails. - """; - - public static void main(String[] args) throws Exception { - PassFailJFrame - .builder() - .title("JComboBoxScrollFocusTest Test Instructions") - .instructions(INSTRUCTIONS) - .columns(40) - .testUI(JComboBoxScrollFocusTest::createAndShowGUI) - .build() - .awaitAndCheck(); - } - - private static JFrame createAndShowGUI() { - JFrame frame = new JFrame("JComboBoxScrollFocusTest Test Frame"); - JComboBox combobox = new JComboBox<>(); - for (int i = 0; i < 100; i++) { - combobox.addItem(String.valueOf(i)); - } - frame.add(combobox); - frame.setSize(400, 200); - frame.setLocationRelativeTo(null); - return frame; - } -} From 5bb73d4876f3bd906d64ce80537cf386dbc7cbc1 Mon Sep 17 00:00:00 2001 From: Damon Nguyen Date: Thu, 17 Apr 2025 09:45:23 -0700 Subject: [PATCH 2/4] Initial opening --- .../javax/swing/JTree/NodeChangedTest.java | 72 +++++++++++ test/jdk/javax/swing/JTree/bug4118860.java | 97 ++++++++++++++ test/jdk/javax/swing/JTree/bug4169215.java | 65 ++++++++++ test/jdk/javax/swing/JTree/bug4196987.java | 70 ++++++++++ test/jdk/javax/swing/JTree/bug4270654.java | 76 +++++++++++ test/jdk/javax/swing/JTree/bug4618767.java | 121 ++++++++++++++++++ 6 files changed, 501 insertions(+) create mode 100644 test/jdk/javax/swing/JTree/NodeChangedTest.java create mode 100644 test/jdk/javax/swing/JTree/bug4118860.java create mode 100644 test/jdk/javax/swing/JTree/bug4169215.java create mode 100644 test/jdk/javax/swing/JTree/bug4196987.java create mode 100644 test/jdk/javax/swing/JTree/bug4270654.java create mode 100644 test/jdk/javax/swing/JTree/bug4618767.java diff --git a/test/jdk/javax/swing/JTree/NodeChangedTest.java b/test/jdk/javax/swing/JTree/NodeChangedTest.java new file mode 100644 index 0000000000000..5461136c57be7 --- /dev/null +++ b/test/jdk/javax/swing/JTree/NodeChangedTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4199472 + * @summary Tests that node changed for the root of the tree update the + * structure. + * @run main NodeChangedTest + */ + +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; + +public class NodeChangedTest { + public static void main(String[] args) { + // Create 3 nodes + final DefaultMutableTreeNode root = new DefaultMutableTreeNode("root", + true); + final DefaultMutableTreeNode child = new DefaultMutableTreeNode("child", + true); + final DefaultMutableTreeNode leaf = new DefaultMutableTreeNode("leaf", + false); + root.add(child); + child.add(leaf); + + final JTree tree = new JTree(root); + + // Change the root node + root.setUserObject("New root"); + ((DefaultTreeModel) tree.getModel()).nodeChanged(root); + + // Check + if (!root.getUserObject().toString().equals("New root")) { + throw new RuntimeException("Failed changing root node for default model."); + } + + // Change to large model + tree.setLargeModel(true); + tree.setRowHeight(20); + root.setUserObject("root"); + tree.setModel(new DefaultTreeModel(root)); + root.setUserObject("New root"); + ((DefaultTreeModel) tree.getModel()).nodeChanged(root); + + // Check again + if (!root.getUserObject().toString().equals("New root")) { + throw new RuntimeException("Failed changing root node for large model."); + } + } +} diff --git a/test/jdk/javax/swing/JTree/bug4118860.java b/test/jdk/javax/swing/JTree/bug4118860.java new file mode 100644 index 0000000000000..eceb11da5dc9c --- /dev/null +++ b/test/jdk/javax/swing/JTree/bug4118860.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4118860 + * @summary setToggleClickCount/getToggleClickCount have been added. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4118860 + */ + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTree; + +public class bug4118860 { + static final String INSTRUCTIONS = """ + Push the "Single Click" button and try expanding/contracting + branch nodes of the tree with one left mouse button click + on the label part of the node (not the icon or handles). + + Then push the "Double Click" button and try doing the same using + left mouse button double click. Single click shouldn't cause + expanding/contracting. A double click should now be required + to expand/contract nodes. + + If it works then the test PASSES, else the test FAILS. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("bug4118860 Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(bug4118860::createUI) + .build() + .awaitAndCheck(); + } + + static JFrame createUI() { + JFrame f = new JFrame("ToggleClickCount Test"); + JTree tr = new JTree(); + JPanel p = new JPanel(); + p.setBackground(Color.red); + p.setLayout(new GridLayout(1, 1)); + tr.setOpaque(false); + p.add(tr); + f.add(p, BorderLayout.CENTER); + JPanel bp = new JPanel(); + JButton bt1 = new JButton("Single Click"); + bt1.addActionListener(e -> { + tr.setToggleClickCount(1); + if (tr.getToggleClickCount() != 1) { + throw new Error("ToggleClickCount doesn't set..."); + } + }); + JButton bt2 = new JButton("Double Click"); + bt2.addActionListener(e -> { + tr.setToggleClickCount(2); + if (tr.getToggleClickCount() != 2) { + throw new Error("ToggleClickCount doesn't set..."); + } + }); + bp.setLayout(new GridLayout(1, 2)); + bp.add(bt1); + bp.add(bt2); + f.add(bp, BorderLayout.SOUTH); + f.setSize(300, 200); + return f; + } +} diff --git a/test/jdk/javax/swing/JTree/bug4169215.java b/test/jdk/javax/swing/JTree/bug4169215.java new file mode 100644 index 0000000000000..0b8780b3939d7 --- /dev/null +++ b/test/jdk/javax/swing/JTree/bug4169215.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4169215 + * @summary Accessibility hierarchy JTree node test. + * @run main bug4169215 + */ + +import javax.accessibility.AccessibleContext; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; + +public class bug4169215 { + public static void main(String[] args) { + // create the tree + DefaultMutableTreeNode root = new DefaultMutableTreeNode("top"); + DefaultMutableTreeNode nodeA = new DefaultMutableTreeNode("A"); + DefaultMutableTreeNode nodeB = new DefaultMutableTreeNode("B"); + root.add(nodeA); + root.add(nodeB); + JTree tree = new JTree(root); + + // find the AccessibleContext of the tree + AccessibleContext actree = tree.getAccessibleContext(); + + // find the AccessibleContext of top node of the tree + AccessibleContext act = actree.getAccessibleChild(0).getAccessibleContext(); + + // find the AccessibleContext of the first child of the table -> + // the AccessibleContext of nodeA + AccessibleContext accA = act.getAccessibleChild(0).getAccessibleContext(); + + // find the AccessibleContext of the next sibling of nodeA, by getting + // child+1 of the parent (the table) + AccessibleContext accB = act.getAccessibleChild( + accA.getAccessibleIndexInParent()+1).getAccessibleContext(); + + // look to see who the sibling is. + if (accB.getAccessibleName().compareTo("B") != 0) { + throw new RuntimeException("Parent node is a sibling instead!"); + } + } +} diff --git a/test/jdk/javax/swing/JTree/bug4196987.java b/test/jdk/javax/swing/JTree/bug4196987.java new file mode 100644 index 0000000000000..1387b669b0560 --- /dev/null +++ b/test/jdk/javax/swing/JTree/bug4196987.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4196987 + * @summary Test Metal L&F JTree expander icons transparency. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4196987 + */ + +import java.awt.Color; +import java.awt.GridLayout; + +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.UIManager; + +public class bug4196987 { + static final String INSTRUCTIONS = """ + If the background of tree icons are red, the test PASSES. + Otherwise the test FAILS. + """; + + public static void main(String[] args) throws Exception { + UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); + PassFailJFrame.builder() + .title("bug4196987 Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(bug4196987::createUI) + .build() + .awaitAndCheck(); + } + + static JFrame createUI() { + JFrame f = new JFrame("JTree Icon Transparency Test"); + JPanel p = new JPanel(); + p.setBackground(Color.red); + p.setLayout(new GridLayout(1, 1)); + JTree t = new JTree(); + t.setOpaque(false); + p.add(t); + f.add(p); + f.setSize(200, 200); + return f; + } +} diff --git a/test/jdk/javax/swing/JTree/bug4270654.java b/test/jdk/javax/swing/JTree/bug4270654.java new file mode 100644 index 0000000000000..413626d788158 --- /dev/null +++ b/test/jdk/javax/swing/JTree/bug4270654.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 1999, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4270654 + * @summary Tests that selection change in JTree does not cause unnecessary + scrolling. + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4270654 + */ + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; + +public class bug4270654 { + static final String INSTRUCTIONS = """ + Select the "dan" node and scroll to the right a little using the + scrollbar. Then press down arrow key. If the tree unscrolls back + to the left, the test FAILS. Otherwise, the test PASSES. + """; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("bug4270654 Test Instructions") + .instructions(INSTRUCTIONS) + .columns(40) + .testUI(bug4270654::createUI) + .build() + .awaitAndCheck(); + } + + static JFrame createUI() { + JFrame f = new JFrame("JTree Scroll Back Test"); + DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); + String[] lev1 = {"foo", "bar", "dan"}; + String[][] lev2 = { + {}, + {"small", "a nice big node for testing"}, + {"xyz", "pqd", "a really really big node for testing"}}; + for (int i = 0; i < lev1.length; i++) { + DefaultMutableTreeNode child = new DefaultMutableTreeNode(lev1[i]); + root.add(child); + for (int j = 0; j < lev2[i].length; j++) + child.add(new DefaultMutableTreeNode(lev2[i][j])); + } + final JTree tree = new JTree(root); + tree.expandRow(3); + f.add(new JScrollPane(tree)); + f.setSize(200, 200); + return f; + } +} diff --git a/test/jdk/javax/swing/JTree/bug4618767.java b/test/jdk/javax/swing/JTree/bug4618767.java new file mode 100644 index 0000000000000..d8aa52c3952f2 --- /dev/null +++ b/test/jdk/javax/swing/JTree/bug4618767.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2002, 2025, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4618767 + * @summary First letter navigation in JTree interferes with mnemonics + * @key headful + * @run main bug4618767 + */ + +import java.awt.Robot; +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.awt.event.KeyEvent; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import javax.swing.JFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JTree; +import javax.swing.SwingUtilities; +import javax.swing.event.MenuEvent; +import javax.swing.event.MenuListener; + +public class bug4618767 { + private static JFrame f; + private static final JTree tree = new + JTree(new String[] {"one", "two", "three", "four"}); + private static boolean menuSelected; + private static CountDownLatch listGainedFocusLatch = new CountDownLatch(1); + + public static void main(String[] args) throws Exception { + try { + SwingUtilities.invokeAndWait(() -> { + f = new JFrame("bug4618767 Test"); + JMenu menu = new JMenu("File"); + menu.setMnemonic('F'); + JMenuItem menuItem = new JMenuItem("item"); + menu.add(menuItem); + JMenuBar menuBar = new JMenuBar(); + menuBar.add(menu); + f.setJMenuBar(menuBar); + + menu.addMenuListener(new MenuListener() { + public void menuCanceled(MenuEvent e) {} + public void menuDeselected(MenuEvent e) {} + public void menuSelected(MenuEvent e) { + menuSelected = true; + } + }); + + tree.addFocusListener(new FocusAdapter() { + @Override + public void focusGained(FocusEvent e) { + listGainedFocusLatch.countDown(); + } + }); + f.add(tree); + f.pack(); + f.setLocationRelativeTo(null); + f.setAlwaysOnTop(true); + f.setVisible(true); + }); + runTest(); + } finally { + SwingUtilities.invokeAndWait(() -> { + if (f != null) { + f.dispose(); + } + }); + } + } + + private static void runTest() throws Exception { + if (!listGainedFocusLatch.await(3, TimeUnit.SECONDS)) { + throw new RuntimeException("Waited too long, but can't gain" + + " focus for list"); + } + Robot robot = new Robot(); + robot.setAutoDelay(200); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_O); + robot.keyRelease(KeyEvent.VK_O); + robot.waitForIdle(); + robot.keyPress(KeyEvent.VK_ALT); + robot.keyPress(KeyEvent.VK_F); + robot.keyRelease(KeyEvent.VK_F); + robot.keyRelease(KeyEvent.VK_ALT); + + SwingUtilities.invokeAndWait(() -> { + if (menuSelected && !tree.getSelectionPath() + .getLastPathComponent().toString().equals("one")) { + throw new RuntimeException("Mnemonics interferes with JTree" + + " item selection using KeyEvent"); + } + }); + } +} From c7870e3e80c1b7b10a189aefe36140a188d8acdd Mon Sep 17 00:00:00 2001 From: Damon Nguyen Date: Thu, 17 Apr 2025 10:40:07 -0700 Subject: [PATCH 3/4] Add headful tags --- test/jdk/javax/swing/JTree/NodeChangedTest.java | 1 + test/jdk/javax/swing/JTree/bug4169215.java | 1 + 2 files changed, 2 insertions(+) diff --git a/test/jdk/javax/swing/JTree/NodeChangedTest.java b/test/jdk/javax/swing/JTree/NodeChangedTest.java index 5461136c57be7..aadf390df9966 100644 --- a/test/jdk/javax/swing/JTree/NodeChangedTest.java +++ b/test/jdk/javax/swing/JTree/NodeChangedTest.java @@ -26,6 +26,7 @@ * @bug 4199472 * @summary Tests that node changed for the root of the tree update the * structure. + * @key headful * @run main NodeChangedTest */ diff --git a/test/jdk/javax/swing/JTree/bug4169215.java b/test/jdk/javax/swing/JTree/bug4169215.java index 0b8780b3939d7..e6387a644b6f1 100644 --- a/test/jdk/javax/swing/JTree/bug4169215.java +++ b/test/jdk/javax/swing/JTree/bug4169215.java @@ -25,6 +25,7 @@ * @test * @bug 4169215 * @summary Accessibility hierarchy JTree node test. + * @key headful * @run main bug4169215 */ From 52d78abbc913dbe7d3ffbf7b06fb1dca9e16a1c8 Mon Sep 17 00:00:00 2001 From: Damon Nguyen Date: Fri, 18 Apr 2025 10:10:15 -0700 Subject: [PATCH 4/4] Remove headful tags. Change errors to RE. --- test/jdk/javax/swing/JTree/NodeChangedTest.java | 1 - test/jdk/javax/swing/JTree/bug4118860.java | 4 ++-- test/jdk/javax/swing/JTree/bug4169215.java | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/test/jdk/javax/swing/JTree/NodeChangedTest.java b/test/jdk/javax/swing/JTree/NodeChangedTest.java index aadf390df9966..5461136c57be7 100644 --- a/test/jdk/javax/swing/JTree/NodeChangedTest.java +++ b/test/jdk/javax/swing/JTree/NodeChangedTest.java @@ -26,7 +26,6 @@ * @bug 4199472 * @summary Tests that node changed for the root of the tree update the * structure. - * @key headful * @run main NodeChangedTest */ diff --git a/test/jdk/javax/swing/JTree/bug4118860.java b/test/jdk/javax/swing/JTree/bug4118860.java index eceb11da5dc9c..eb266eb9324ab 100644 --- a/test/jdk/javax/swing/JTree/bug4118860.java +++ b/test/jdk/javax/swing/JTree/bug4118860.java @@ -77,14 +77,14 @@ static JFrame createUI() { bt1.addActionListener(e -> { tr.setToggleClickCount(1); if (tr.getToggleClickCount() != 1) { - throw new Error("ToggleClickCount doesn't set..."); + throw new RuntimeException("ToggleClickCount doesn't set..."); } }); JButton bt2 = new JButton("Double Click"); bt2.addActionListener(e -> { tr.setToggleClickCount(2); if (tr.getToggleClickCount() != 2) { - throw new Error("ToggleClickCount doesn't set..."); + throw new RuntimeException("ToggleClickCount doesn't set..."); } }); bp.setLayout(new GridLayout(1, 2)); diff --git a/test/jdk/javax/swing/JTree/bug4169215.java b/test/jdk/javax/swing/JTree/bug4169215.java index e6387a644b6f1..0b8780b3939d7 100644 --- a/test/jdk/javax/swing/JTree/bug4169215.java +++ b/test/jdk/javax/swing/JTree/bug4169215.java @@ -25,7 +25,6 @@ * @test * @bug 4169215 * @summary Accessibility hierarchy JTree node test. - * @key headful * @run main bug4169215 */