Java Swing : GUI frozen - jstack interpretation

前端 未结 3 1191
再見小時候
再見小時候 2020-12-21 01:42

I have a Gui application in swing that prints a ticket on a serial thermal printer. When i hit the button that launch this action, my GUI is frozen. I think that\'s because

3条回答
  •  没有蜡笔的小新
    2020-12-21 01:45

    One very basic rule:

    • Keep the UI work on the UI thread, and the Non-UI work on the Non-UI thread.

    This way we can keep the GUI interactive and responsive.

    • In Java Event Dispatcher Thread (EDT) is the UI thread, main() method in Java GUI application is not long lived, so after scheduling the work of GUI construction in the Event Dispatcher Queue it quits and then it's EDT that handles the GUI.

    • Either use Thread to do the Long Non-UI processing work, or use SwingWorker, this is provided in java to do a seamless synchronization between the UI and Non-UI work......

提交回复
热议问题