Skip to content

Commit

Permalink
8247163: JFXPanel throws exception on click when no Scene is set
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
FlorianKirmaier authored and kevinrushforth committed Jun 17, 2020
1 parent 54e2507 commit 1727dfa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,10 @@ protected void processMouseEvent(MouseEvent e) {
// The extra simulated mouse pressed event is removed by making the JavaFX scene focused.
// It is safe, because in JavaFX only the method "setFocused(true)" is called,
// which doesn't have any side-effects when called multiple times.
int focusCause = AbstractEvents.FOCUSEVENT_ACTIVATED;
stagePeer.setFocused(true, focusCause);
if (stagePeer != null) {
int focusCause = AbstractEvents.FOCUSEVENT_ACTIVATED;
stagePeer.setFocused(true, focusCause);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,23 @@ public void testNoDoubleClickOnFirstClick() throws Exception {

Assert.assertEquals(1, pressedEventCounter[0]);
}

@Test
public void testClickOnEmptyJFXPanel() throws Exception {
CountDownLatch firstPressedEventLatch = new CountDownLatch(1);

SwingUtilities.invokeLater(() -> {
TestFXPanel fxPnl = new TestFXPanel();

MouseEvent e = new MouseEvent(fxPnl, MouseEvent.MOUSE_PRESSED, 0, MouseEvent.BUTTON1_DOWN_MASK,
5, 5, 1, false, MouseEvent.BUTTON1);

fxPnl.processMouseEventPublic(e);

firstPressedEventLatch.countDown();
});

Assert.assertTrue(firstPressedEventLatch.await(5000, TimeUnit.MILLISECONDS));
}
}

0 comments on commit 1727dfa

Please sign in to comment.