What I'm trying to do is printing texts on textarea in real time even after the button is clicked.
When I click the button, the UI freezes until its job finishes, and after that, it prints all the texts together unlike System.out.println.
The code below is what I tried, and it doesn't work as I expected. UI just hangs and doesn't show me 'test' on textarea.
There's no need to use the listener, and it's okay to use appendText only, but I just can't find out how to let the ActionEvent for the button work without freezing the UI.
I will really appreciate your any help or much better code!!
final TextField announcement = new TextField();
Platform.runLater(new Runnable() {
@Override public void run() {
announcement.textProperty().addListener(new javafx.beans.value.ChangeListener<String>() {
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
textoutput.appendText(announcement.getText());
}
});
}
});
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
announcement.setText("test");
// bunch of codes below
}
});