How to update JFrame Label within a Thread? - Java

后端 未结 5 1489
南笙
南笙 2021-01-19 02:20

I have tried a lot, but can\'t seem to get it to work.

I was told to use EDT with the following example.

    SwingUtilities.invokeLater(new Runnable(         


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-19 03:06

    This is a pretty common element of all GUI programming. You have one thread that handles drawing the GUI, getting input, and running callbacks. If another thread tries to change the GUI related objects, it will conflict with the GUI thread. Say, for example, it was half way through drawing something and you change the color from a different thread.

    All invokeLater does is queue up something for the GUI thread to run. By "later" it's really runs almost instantly but the current thread doesn't have to wait for it. The GUI thread may be doing a draw or waiting for a callback to return which would delay executing the code you gave it.

提交回复
热议问题