Skip to content

Commit 7465de4

Browse files
committed
6603771: Nimbus L&F: Ctrl+F7 keybinding for Jinternal Frame throws a NPE.
Reviewed-by: abhiscxk, serb
1 parent fbe5ab0 commit 7465de4

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicDesktopPaneUI.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ else if (LEFT == key ||
438438
}
439439
Insets minOnScreenInsets =
440440
UIManager.getInsets("Desktop.minOnScreenInsets");
441+
if (minOnScreenInsets == null) {
442+
minOnScreenInsets = new Insets(0, 0, 0, 0);
443+
}
441444
Dimension size = c.getSize();
442445
Dimension minSize = c.getMinimumSize();
443446
int dpWidth = dp.getWidth();
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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+
/*
24+
* @test
25+
* @key headful
26+
* @bug 6603771
27+
* @summary Verifies Nimbus L&F: Ctrl+F7 keybinding for Jinternal Frame throws a NPE
28+
* @run main JInternalFrameTest
29+
*/
30+
import java.awt.BorderLayout;
31+
import java.awt.Dimension;
32+
import java.awt.EventQueue;
33+
import java.awt.Point;
34+
import java.awt.Rectangle;
35+
import java.awt.Robot;
36+
import java.awt.event.InputEvent;
37+
import java.awt.event.KeyEvent;
38+
import javax.swing.JDesktopPane;
39+
import javax.swing.JFrame;
40+
import javax.swing.JInternalFrame;
41+
import javax.swing.JPanel;
42+
import javax.swing.SwingUtilities;
43+
import javax.swing.UIManager;
44+
import javax.swing.UnsupportedLookAndFeelException;
45+
46+
public class JInternalFrameTest {
47+
static JFrame jFrame;
48+
static JInternalFrame iFrame;
49+
static boolean isAquaLAF;
50+
static int controlKey;
51+
52+
volatile static boolean failed = false;
53+
54+
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
55+
try {
56+
UIManager.setLookAndFeel(laf.getClassName());
57+
} catch (UnsupportedLookAndFeelException ignored) {
58+
System.out.println("Unsupported L&F: " + laf.getClassName());
59+
} catch (ClassNotFoundException | InstantiationException
60+
| IllegalAccessException e) {
61+
throw new RuntimeException(e);
62+
}
63+
}
64+
65+
public static void main(String[] args) throws Exception {
66+
Robot robot = new Robot();
67+
EventQueue.invokeAndWait(
68+
() -> Thread.currentThread().setUncaughtExceptionHandler(
69+
(t, e) -> {
70+
failed = true;
71+
}
72+
));
73+
for (UIManager.LookAndFeelInfo laf :
74+
UIManager.getInstalledLookAndFeels()) {
75+
System.out.println("Testing L&F: " + laf.getClassName());
76+
SwingUtilities.invokeAndWait(() -> setLookAndFeel(laf));
77+
try {
78+
SwingUtilities.invokeAndWait(() -> createUI());
79+
robot.waitForIdle();
80+
robot.delay(1000);
81+
82+
Point pt = iFrame.getLocationOnScreen();
83+
Rectangle dim = iFrame.getBounds();
84+
robot.mouseMove(pt.x + dim.width/3, pt.y+10);
85+
robot.waitForIdle();
86+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
87+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
88+
robot.waitForIdle();
89+
robot.delay(1000);
90+
robot.keyPress(KeyEvent.VK_CONTROL);
91+
robot.keyPress(KeyEvent.VK_F7);
92+
robot.keyRelease(KeyEvent.VK_F7);
93+
robot.keyRelease(KeyEvent.VK_CONTROL);
94+
robot.waitForIdle();
95+
robot.delay(1000);
96+
robot.keyPress(KeyEvent.VK_UP);
97+
robot.keyRelease(KeyEvent.VK_UP);
98+
robot.waitForIdle();
99+
robot.delay(1000);
100+
if (failed) {
101+
throw new RuntimeException("Exception thrown");
102+
}
103+
} finally {
104+
SwingUtilities.invokeAndWait(() -> {
105+
if (jFrame != null) {
106+
jFrame.dispose();
107+
}
108+
});
109+
}
110+
}
111+
}
112+
113+
private static void createUI() {
114+
jFrame = new JFrame();
115+
116+
JDesktopPane desktopPane = new JDesktopPane();
117+
118+
iFrame = new JInternalFrame("Test");
119+
iFrame.setTitle("InternalFrame");
120+
iFrame.setLocation(50, 50);
121+
iFrame.setSize(200, 200);
122+
iFrame.setVisible(true);
123+
124+
desktopPane.add(iFrame);
125+
126+
JPanel panel = new JPanel();
127+
panel.setLayout(new BorderLayout());
128+
panel.add(desktopPane, BorderLayout.CENTER);
129+
130+
jFrame.add(panel, BorderLayout.CENTER);
131+
jFrame.setSize(400, 400);
132+
jFrame.setLocationRelativeTo(null);
133+
jFrame.setVisible(true);
134+
}
135+
}

0 commit comments

Comments
 (0)