JavaFX Thread freeze

前端 未结 2 763
南旧
南旧 2021-01-28 23:56

I\'m currently working on a JavaFX project. On GUI initialization I want to read some infos out of a HTML document using Selenium and FirefoxDriver. Normally I would use a crawl

相关标签:
2条回答
  • 2021-01-29 00:40
    1. You look to be trying to make JavaFX calls directly from within a background thread, and while I know little about JavaFX, I do know that this is not allowed, that JavaFX calls must be made on the JavaFX Application thread. See Concurrency in JavaFX.
    2. You're not even creating a background thread. You call st.run(); which runs st on the calling thread -- not what you want. You should be calling st.start()!
    3. As a side note, you seem to be extending Thread where you really want to be implementing Runnable. Thus you really should be calling new Thread(myRunnable).start();
    0 讨论(0)
  • 2021-01-29 00:43

    You are trying to update the UI from a different thread. The UI can only be updated from the UI thread. To achieve this, wrap the calls to update the progress:

    Platform.runLater(() -> {main.getPbStart().setProgress(0.65);});
    

    This will push the update of the UI into the UI thread.

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