JavaFx answer to SwingUtilities.invokeLater

So, I know that the JavaFx update method when using a thread is called Task, but is the code working the same way or is there any difference. let me give an example of a swing:

Another class outside the GUI that works like a thread

public void run(){ while (socket.isConnected()) { String x = input.next(); System.out.println(x); mg.updateChat(x) } } 

Inside GUI

 public void updateChat(final String input){ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { txtChat.setText(input); } }); } 

Does the task work exactly the same? Or are there differences, and is there a way to change this code to work in a JavaFx project?

+8
java swing javafx event-dispatch-thread
source share
1 answer

You are looking for SwingUtil.invokeLater in JavaFX. If yes, this is:

 Platform.runLater(java.lang.Runnable runnable) 
+15
source share

All Articles