I make board game in javafx and I stumbled upon a problem. My application has Client/Server connection. Whenever server sends data about where player moved his pawn I call a fun
Clearly Client.run() is being executed on a background thread, and calls Controller.movePawn(), which (via refresh()) updates the UI. You cannot update the UI on a background thread. You need to wrap the code that updates the UI in Platform.runLater(). So, it's pretty hard to tell without a complete example, but using that particular sequence of method calls as an example, it looks like you need to do
public void movePawn(int x1, int y1, int x2, int y2) {
Platform.runLater(() -> {
Pawn pawnTemp = game.getBoard().getField(x1, y1).getPawn();
game.getBoard().getField(x1, y1).setPawn(null);
game.getBoard().getField(x2, y2).setPawn(pawnTemp);
refresh();
});
}
There are probably similar issues throughout the code, but the bottom line is that you: