JavaFX append text to TextArea throws Exception

前端 未结 1 762
误落风尘
误落风尘 2020-12-11 16:41

Answer : JavaFX append text to TextArea throws Exception

I have a thread that calculates the size of a directory.

I use walkFileTree for this.

To get

相关标签:
1条回答
  • 2020-12-11 17:09

    Ran into same error and as kleopatra's comment stated, FX textarea must be accessed on FX thread.

    For simple cases, use Platform.runLater with Java 8 Lambda:

    javafx.application.Platform.runLater( () -> taStatus.appendText(file.toString() + "\n") );
    

    If you have many log messages, instead of flooding the FX thread it would be better to buffer them and update TextArea less frequently. Here is an example: https://stackoverflow.com/a/31414801/3710098

    0 讨论(0)
提交回复
热议问题