From 0c5b74b976ae5eeb90c05a12022e25ce05a4fded Mon Sep 17 00:00:00 2001 From: delvh Date: Thu, 9 Apr 2020 22:30:24 +0200 Subject: [PATCH] Performed updating of the UI on the UI thread --- .gitignore | 5 ++++- src/main/java/envoy/client/ui/ChatSceneController.java | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a6f89c2..e01c619 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/target/ \ No newline at end of file +/target/ + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* diff --git a/src/main/java/envoy/client/ui/ChatSceneController.java b/src/main/java/envoy/client/ui/ChatSceneController.java index 1882fba..b8927d4 100644 --- a/src/main/java/envoy/client/ui/ChatSceneController.java +++ b/src/main/java/envoy/client/ui/ChatSceneController.java @@ -17,6 +17,7 @@ import envoy.event.EventBus; import envoy.event.MessageStatusChangeEvent; import envoy.event.UserStatusChangeEvent; import envoy.util.EnvoyLog; +import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.fxml.FXML; import javafx.scene.control.*; @@ -74,7 +75,7 @@ public final class ChatSceneController { chat.getMessages().add(message); // Update UI if in current chat - if (chat == currentChat) messageList.getItems().add(message); + if (chat == currentChat) Platform.runLater(() -> messageList.getItems().add(message)); }); // Listen to message status changes @@ -83,11 +84,11 @@ public final class ChatSceneController { message.setStatus(e.get()); // Update UI if in current chat - if (currentChat != null && message.getSenderID() == currentChat.getRecipient().getID()) messageList.refresh(); + if (currentChat != null && message.getSenderID() == currentChat.getRecipient().getID()) Platform.runLater(() -> messageList.refresh()); }); // Listen to user status changes - eventBus.register(UserStatusChangeEvent.class, e -> userList.refresh()); + eventBus.register(UserStatusChangeEvent.class, e -> Platform.runLater(() -> userList.refresh())); } void initializeData(LocalDB localDB, Client client, WriteProxy writeProxy) { @@ -96,7 +97,6 @@ public final class ChatSceneController { this.writeProxy = writeProxy; // TODO: handle offline mode - // userList.setItems(FXCollections.observableList(client.getContacts())); userList.setItems(FXCollections.observableList(localDB.getUser().getContacts().stream().collect(Collectors.toList()))); }