Skip to content

8360462: [macosx] row selection not working with Ctrl+Shift+Down/Up in AquaL&F #25966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
Expand Down Expand Up @@ -423,10 +423,14 @@ LateBoundInputMap getTreeInputMap() {
"KP_UP", "selectPrevious",
"shift UP", "selectPreviousExtendSelection",
"shift KP_UP", "selectPreviousExtendSelection",
"shift ctrl UP", "selectPreviousExtendSelection",
"shift ctrl KP_UP", "selectPreviousExtendSelection",
"DOWN", "selectNext",
"KP_DOWN", "selectNext",
"shift DOWN", "selectNextExtendSelection",
"shift KP_DOWN", "selectNextExtendSelection",
"shift ctrl DOWN", "selectNextExtendSelection",
"shift ctrl KP_DOWN", "selectNextExtendSelection",
"RIGHT", "aquaExpandNode",
"KP_RIGHT", "aquaExpandNode",
"LEFT", "aquaCollapseNode",
Expand Down
113 changes: 113 additions & 0 deletions test/jdk/javax/swing/JTree/TestTreeRowSelection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* Copyright (c) 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
* @key headful
* @requires (os.family == "mac")
* @bug 8360462
* @summary Verifies ctrl+shift+down selects next row
* and ctrl+shift+up selects previous row in Aqua L&F
* @run main TestTreeRowSelection
*/

import java.awt.Robot;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.tree.DefaultMutableTreeNode;

public class TestTreeRowSelection {
static JTree tree;
static JFrame frame;
static volatile int selectedRowCount;
static volatile int curSelectedRowCount;

public static void main(String[] args) throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws Exception {


try {
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
DefaultMutableTreeNode sports = new DefaultMutableTreeNode("sports");
sports.add(new DefaultMutableTreeNode("basketball"));
sports.add(new DefaultMutableTreeNode("football"));
sports.add(new DefaultMutableTreeNode("cricket"));
sports.add(new DefaultMutableTreeNode("tennis"));

tree = new JTree(sports);
tree.setSelectionRow(2);

frame.getContentPane().add(tree);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
Robot robot = new Robot();
robot.waitForIdle();
robot.delay(1000);
SwingUtilities.invokeAndWait(() -> {
selectedRowCount = tree.getSelectionCount();
});
System.out.println("rows selected " + selectedRowCount);
for (int i = 0; i < 2; i++) {
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_DOWN);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.waitForIdle();
robot.delay(500);
}
SwingUtilities.invokeAndWait(() -> {
curSelectedRowCount = tree.getSelectionCount();
});
System.out.println("rows selected " + curSelectedRowCount);
if (curSelectedRowCount != selectedRowCount + 2) {
throw new RuntimeException("ctrl+shift+down doesn't select next row");
}
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_SHIFT);
robot.keyPress(KeyEvent.VK_UP);
robot.keyRelease(KeyEvent.VK_UP);
robot.keyRelease(KeyEvent.VK_SHIFT);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.waitForIdle();
robot.delay(500);
SwingUtilities.invokeAndWait(() -> {
curSelectedRowCount = tree.getSelectionCount();
});
System.out.println("rows selected " + curSelectedRowCount);
if (curSelectedRowCount != selectedRowCount + 1) {
throw new RuntimeException("ctrl+shift+up doesn't select previous row");
}
} finally {
SwingUtilities.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}