Answer the question
In order to leave comments, you need to log in
How to correctly organize the transmission of an event from a separate thread to the GUI on JavaFx?
I have a MainController and a UDPServer class that spins in a separate thread and waits for a message, when a message arrives I need to display it on the GUI. How to organize such interaction?
public class UDPServer implements Runnable {
// ...
@Override
public void run() {
// ...
if(message.equals("N1-M")){
// пришло сообщение и нужно отобразить его в GUI
// в моем случае отобразить значит изменить цвет vRectangle
}
// ...
}
}
public class MainController {
// ...
@FXML Rectangle vRectangle;
// ...
}
Answer the question
In order to leave comments, you need to log in
When you need to perform some action on the JavaFx thread, you need to call Platform.runLater(Runnable r)
. Those. In the argument, you specify the action that will then be performed. The action is non-blocking and asynchronous. Waiting for the end of this action is already a more difficult task and quite another.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question