Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Trying to update UI with from another thread

992276Feb 20 2013 — edited Feb 22 2013
Hi,

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);+
+}+
+}+
+});+
+}+
+}+
This post has been answered by James_D on Feb 20 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2013
Added on Feb 20 2013
5 comments
4,281 views