Before I start: I'm a newbee in JavaFX and with this project i want to learn how to use this library properly.
The situation is the following: i have a server-client application. The server sends the client a list of the active users on the server. Now i want to list the active users in the UI. I wanted to do that with buttons in FlowPane. The problem is that my client is in an external thread, so not in the application-thread. But because of the fact that the client gets the list on users, I tried to update the button-list directly from the client-thread.
if(data.getObject() instanceof ArrayList<?>) {
ArrayList<User> activeUsers = (ArrayList<User>) data.getObject();
controller.setActiveUsers(activeUsers);
}
The method in my controller does the following:
public void setActiveUsers(ArrayList<User> activeUsers) {
for(User user:activeUsers) {
fpOnlineUsers.getChildren().add(new Button(user.getName()));
}
}
The Exception i get is the following:java.lang.IllegalStateException: Not on FX application thread; currentThread = Thread-3
I have two questions:
- How can i fix this?
- Why blocks JavaFX changed made from threads other than the application-thread?
Please apologize any language mistakes, I'm not a native speaker :)