Skip to content

Commit 420a68e

Browse files
author
Andrew Lu
committedDec 11, 2023
7148092: [macosx] When Alt+down arrow key is pressed, the combobox popup does not appear.
Backport-of: c42ef70a453690ecdccc570161fdfda58318ecc6
1 parent 05bb69d commit 420a68e

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
 

‎src/java.desktop/macosx/classes/com/apple/laf/AquaComboBoxUI.java

+23
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ protected void installKeyboardActions() {
323323
actionMap.put("aquaSelectPageDown", highlightPageDownAction);
324324

325325
actionMap.put("aquaHidePopup", hideAction);
326+
actionMap.put("aquaOpenPopupOrhighlightLast", openPopupOrHighlightLast);
327+
actionMap.put("aquaOpenPopupOrhighlightFirst", openPopupOrHighlightFirst);
326328

327329
SwingUtilities.replaceUIActionMap(comboBox, actionMap);
328330
}
@@ -581,6 +583,27 @@ public boolean isEnabled() {
581583
}
582584
};
583585

586+
@SuppressWarnings("serial") // anonymous class
587+
private final Action openPopupOrHighlightLast = new ComboBoxAction() {
588+
@Override
589+
void performComboBoxAction(final AquaComboBoxUI ui) {
590+
final int size = listBox.getModel().getSize();
591+
listBox.setSelectedIndex(size - 1);
592+
listBox.ensureIndexIsVisible(size - 1);
593+
comboBox.setSelectedIndex(ui.getPopup().getList().getSelectedIndex());
594+
}
595+
};
596+
597+
@SuppressWarnings("serial") // anonymous class
598+
private final Action openPopupOrHighlightFirst = new ComboBoxAction() {
599+
@Override
600+
void performComboBoxAction(final AquaComboBoxUI ui) {
601+
listBox.setSelectedIndex(0);
602+
listBox.ensureIndexIsVisible(0);
603+
comboBox.setSelectedIndex(ui.getPopup().getList().getSelectedIndex());
604+
}
605+
};
606+
584607
public void applySizeFor(final JComponent c, final Size size) {
585608
if (arrowButton == null) return;
586609
final Border border = arrowButton.getBorder();

‎src/java.desktop/macosx/classes/com/apple/laf/AquaKeyBindings.java

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ LateBoundInputMap getComboBoxInputMap() {
220220
"KP_UP", "aquaSelectPrevious",
221221
"DOWN", "aquaSelectNext",
222222
"KP_DOWN", "aquaSelectNext",
223+
"alt DOWN", "aquaOpenPopupOrhighlightLast",
224+
"alt KP_DOWN", "aquaOpenPopupOrhighlightLast",
225+
"alt UP", "aquaOpenPopupOrhighlightFirst",
226+
"alt KP_UP", "aquaOpenPopupOrhighlightFirst",
223227
"SPACE", "aquaSpacePressed" // "spacePopup"
224228
}));
225229
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright (c) 2022, 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+
/* @test
24+
* @bug 7148092
25+
* @requires (os.family == "mac")
26+
* @summary Tests that alt+down arrow pulls down JComboBox popup
27+
* @key headful
28+
* @run main TestAltUpDownComboBox
29+
*/
30+
31+
import java.awt.Container;
32+
import java.awt.Robot;
33+
import java.awt.event.KeyEvent;
34+
import javax.swing.BoxLayout;
35+
import javax.swing.JFrame;
36+
import javax.swing.JComboBox;
37+
import javax.swing.SwingUtilities;
38+
39+
public class TestAltUpDownComboBox {
40+
41+
private static JFrame frame;
42+
private static JComboBox combo;
43+
44+
public static void main(String[] argv) throws Exception {
45+
Robot robot = new Robot();
46+
robot.setAutoDelay(100);
47+
try {
48+
SwingUtilities.invokeAndWait(() -> {
49+
frame = new JFrame("");
50+
Object[] fruits = {"Banana", "Pear", "Apple"};
51+
combo = new JComboBox(fruits);
52+
Container pane = frame.getContentPane();
53+
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
54+
pane.add(combo);
55+
56+
frame.pack();
57+
frame.setLocationRelativeTo(null);
58+
frame.setVisible(true);
59+
});
60+
robot.waitForIdle();
61+
robot.delay(1000);
62+
robot.keyPress(KeyEvent.VK_ALT);
63+
robot.keyPress(KeyEvent.VK_DOWN);
64+
robot.keyRelease(KeyEvent.VK_DOWN);
65+
robot.keyRelease(KeyEvent.VK_ALT);
66+
robot.delay(1000);
67+
68+
if (!combo.isPopupVisible()) {
69+
throw new RuntimeException("comboBox is not visible");
70+
}
71+
72+
robot.keyPress(KeyEvent.VK_ALT);
73+
robot.keyPress(KeyEvent.VK_DOWN);
74+
robot.keyRelease(KeyEvent.VK_DOWN);
75+
robot.keyRelease(KeyEvent.VK_ALT);
76+
robot.delay(1000);
77+
78+
if (combo.getSelectedIndex() != combo.getItemCount() - 1) {
79+
System.out.println(combo.getSelectedIndex());
80+
throw new RuntimeException("Alt+Down did not select last entry");
81+
}
82+
83+
robot.keyPress(KeyEvent.VK_ALT);
84+
robot.keyPress(KeyEvent.VK_UP);
85+
robot.keyRelease(KeyEvent.VK_UP);
86+
robot.keyRelease(KeyEvent.VK_ALT);
87+
robot.delay(1000);
88+
89+
if (combo.getSelectedIndex() != 0) {
90+
System.out.println(combo.getSelectedIndex());
91+
throw new RuntimeException("Alt+Up did not select first entry");
92+
}
93+
} finally {
94+
SwingUtilities.invokeAndWait(() -> {
95+
if (frame != null) {
96+
frame.dispose();
97+
}
98+
});
99+
}
100+
}
101+
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Dec 11, 2023

@openjdk-notifier[bot]
Please sign in to comment.