Good time of day.
To begin, I will describe the situation: There is a TabPane
, on each tab of which there is a User
object, which is updated every n
seconds (receiving data from the server), and if a change occurs, it adds to the Set<User>
(one for all tabs) this user.
What is the problem: I need to update the display of my UI
for each tab, where user data has changed. All the logic is already written, it remains only to figure out how to make the update happen every k
seconds. Creating a new thread is not an option, since Not on FX application thread
thrown when trying to change the state of a UI-компонента
from another thread. And to twist while(true)
in this thread and to sleep there for a few seconds is also not an option, because the main thread of the application will fall asleep and everything will just hang.
How can I implement everything so that the UI
is updated normally? Once again, the main logic has already been written, that is, I can call the updateUI()
method, which will launch a new stream using Platform.runLater(Thread)
, update the mapping and finish.
while (true)
withThread.sleep
and, if necessary, to go to Guy to callPlatform.runLater(runnable)
? If an exception is thrown about the stream, it means that you climb into the gui outside of therunLater
. - Athari