GUI Freezes During While Loop in Java

亡梦爱人 提交于 2019-12-02 09:42:11

You have an infinite loop. The state of the toggle button is never changed after being set to true.

Java's UI (and all UI I've worked with) is driven by a single thread. User input is fed back to you on this single thread. Rendering is also done on this single thread.

The reason the textfield is never updated is the UI thread is never getting to render the screen again, as its tied up in your infinite loop.

Yes, you need to put this code in a separate thread, and start it when the toggle button becomes selected. Then, you need to update the textfield from this separate thread. Look into SwingWorker.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!