Skip to content
Closed
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
Expand Up @@ -299,12 +299,14 @@ public void setScene(final Scene newScene) {
(PrivilegedAction<EventQueue>) java.awt.Toolkit
.getDefaultToolkit()::getSystemEventQueue);
SecondaryLoop secondaryLoop = eventQueue.createSecondaryLoop();
if (secondaryLoop.enter()) {
Platform.runLater(() -> {
Platform.runLater(() -> {
try {
setSceneImpl(newScene);
});
secondaryLoop.exit();
}
} finally {
secondaryLoop.exit();
}
});
secondaryLoop.enter();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.Assume;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import junit.framework.AssertionFailedError;
Expand All @@ -54,6 +55,8 @@ public class JFXPanelTest {
// Used to launch the application before running any test
private static final CountDownLatch launchLatch = new CountDownLatch(1);

JFrame jframe;

// Application class. An instance is created and initialized before running
// the first test, and it lives through the execution of all tests.
public static class MyApp extends Application {
Expand Down Expand Up @@ -84,6 +87,13 @@ public static void doTeardownOnce() {
Platform.exit();
}

@After
public void doCleanup() {
if (jframe != null) {
SwingUtilities.invokeLater(() -> jframe.dispose());
}
}

static class TestFXPanel extends JFXPanel {
protected void processMouseEventPublic(MouseEvent e) {
processMouseEvent(e);
Expand All @@ -103,7 +113,7 @@ public void testNoDoubleClickOnFirstClick() throws Exception {
dummyFXPanel.setPreferredSize(new Dimension(100, 100));
TestFXPanel fxPnl = new TestFXPanel();
fxPnl.setPreferredSize(new Dimension(100, 100));
JFrame jframe = new JFrame();
jframe = new JFrame();
JPanel jpanel = new JPanel();
jpanel.add(dummyFXPanel);
jpanel.add(fxPnl);
Expand Down Expand Up @@ -155,5 +165,58 @@ public void testClickOnEmptyJFXPanel() throws Exception {

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

@Test
public void setSceneOnFXThread() throws Exception {

CountDownLatch completionLatch = new CountDownLatch(1);

SwingUtilities.invokeLater(() -> {
JFXPanel fxPanel = new JFXPanel();
fxPanel.setPreferredSize(new Dimension(100, 100));
jframe = new JFrame();
JPanel jpanel = new JPanel();
jpanel.add(fxPanel);
jframe.add(jpanel);
jframe.pack();
jframe.setVisible(true);

Platform.runLater(() -> {
Scene scene = new Scene(new Group());
fxPanel.setScene(scene);
completionLatch.countDown();
});
});

Assert.assertTrue("Timeout waiting for setScene to complete",
completionLatch.await(5000, TimeUnit.MILLISECONDS));
}

@Test
public void setSceneOnSwingThread() throws Exception {

CountDownLatch completionLatch = new CountDownLatch(1);

SwingUtilities.invokeLater(() -> {
JFXPanel fxPanel = new JFXPanel();
fxPanel.setPreferredSize(new Dimension(100, 100));
jframe = new JFrame();
JPanel jpanel = new JPanel();
jpanel.add(fxPanel);
jframe.add(jpanel);
jframe.pack();
jframe.setVisible(true);

Platform.runLater(() -> {
Scene scene = new Scene(new Group());
SwingUtilities.invokeLater(() -> {
fxPanel.setScene(scene);
completionLatch.countDown();
});
});
});

Assert.assertTrue("Timeout waiting for setScene to complete",
completionLatch.await(5000, TimeUnit.MILLISECONDS));
}
}