Browse Source

Fixed threading bug

proto
Thomas Johnson 2 years ago
parent
commit
ff5c998b06
  1. 18
      window/ChatWindow.java

18
window/ChatWindow.java

@ -1,6 +1,7 @@
package window;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
@ -87,15 +88,18 @@ public class ChatWindow extends Application {
}
}
public void addMessage(String user, String message) { addMessage(user, message, true); }
public void addMessage(String user, String message) { Platform.runLater(() -> addMessage(user, message, true)); }
public void addMessage(String user, String message, boolean doTimestamp) {
String timestamp = doTimestamp ? (new Date()).toString() : "";
Label messageLabel = new Label();
messageLabel.textProperty().setValue(messageLabel.textProperty().getValue() + timestamp + ": [" + user + "] " + message);
messageLabel.setWrapText(true);
messageLabel.prefWidthProperty().bind(messagePane.prefWidthProperty());
messagePane.getChildren().add(messageLabel);
Platform.runLater(() ->
{
String timestamp = doTimestamp ? (new Date()).toString() : "";
Label messageLabel = new Label();
messageLabel.textProperty().setValue(messageLabel.textProperty().getValue() + timestamp + ": [" + user + "] " + message);
messageLabel.setWrapText(true);
messageLabel.prefWidthProperty().bind(messagePane.prefWidthProperty());
messagePane.getChildren().add(messageLabel);
});
}
@Override

Loading…
Cancel
Save