Skip to content

Commit 1727dfa

Browse files
FlorianKirmaierkevinrushforth
authored andcommitted
8247163: JFXPanel throws exception on click when no Scene is set
Reviewed-by: kcr
1 parent 54e2507 commit 1727dfa

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,10 @@ protected void processMouseEvent(MouseEvent e) {
449449
// The extra simulated mouse pressed event is removed by making the JavaFX scene focused.
450450
// It is safe, because in JavaFX only the method "setFocused(true)" is called,
451451
// which doesn't have any side-effects when called multiple times.
452-
int focusCause = AbstractEvents.FOCUSEVENT_ACTIVATED;
453-
stagePeer.setFocused(true, focusCause);
452+
if (stagePeer != null) {
453+
int focusCause = AbstractEvents.FOCUSEVENT_ACTIVATED;
454+
stagePeer.setFocused(true, focusCause);
455+
}
454456
}
455457
}
456458

tests/system/src/test/java/test/javafx/embed/swing/JFXPanelTest.java

+18
Original file line numberDiff line numberDiff line change
@@ -137,5 +137,23 @@ public void testNoDoubleClickOnFirstClick() throws Exception {
137137

138138
Assert.assertEquals(1, pressedEventCounter[0]);
139139
}
140+
141+
@Test
142+
public void testClickOnEmptyJFXPanel() throws Exception {
143+
CountDownLatch firstPressedEventLatch = new CountDownLatch(1);
144+
145+
SwingUtilities.invokeLater(() -> {
146+
TestFXPanel fxPnl = new TestFXPanel();
147+
148+
MouseEvent e = new MouseEvent(fxPnl, MouseEvent.MOUSE_PRESSED, 0, MouseEvent.BUTTON1_DOWN_MASK,
149+
5, 5, 1, false, MouseEvent.BUTTON1);
150+
151+
fxPnl.processMouseEventPublic(e);
152+
153+
firstPressedEventLatch.countDown();
154+
});
155+
156+
Assert.assertTrue(firstPressedEventLatch.await(5000, TimeUnit.MILLISECONDS));
157+
}
140158
}
141159

0 commit comments

Comments
 (0)