Trying to update UI with from another thread
992276Feb 20 2013 — edited Feb 22 2013Hi,
I start a JavaFX application from another class, and then I want to modify UI components from it. I have been trying to use Platform.runLater to do it.
But the GUI hangs initially (doesnt display anything) for the first 5 seconds (sleep time) and then modifies and shows it.
I want to display the GUI at first, and then after 5 seconds the GUI should update with the message, but with the below code it just hangs first and displays everything after 5seconds.
Here sampleGUI is a a javafx app with text fields in it.
+public class StartGame extends Application {+
+@Override+
+public void start(Stage stage) throws Exception {+
final sampleGUI gui = new sampeGUI();
gui.start(stage);
+Platform.runLater(new Runnable() {+
+@Override+
+public void run() {+
+try {+
System.out.println("Sleeping now...");
Thread.sleep(5000);
System.out.println("Sleep over!");
gui.updateText("New message");
+} catch (InterruptedException ex) {+
System.out.println("exception" ex);+
+}+
+}+
+});+
+}+
+}+