java swing program not closing after dispose is called on last window

风流意气都作罢 提交于 2019-12-02 04:26:59

Because dispose() method only releases the resources.

The doc has a

Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information.

Did you notice the may?

The link above gives you detailed information about the Auto shutdown feature. You can read more about that, or you can simply solve this by replacing this.dispose() with System.exit(0)

This Pushing Pixels article: AWT shutdown and daemon threads discusses the AWT shutdown behaviour that was changed in 1.4. Still, the article notes that it can be tricky to get a clean shutdown.

Without seeing the rest of the code, I can only offer pointers:

  • ensure there are no other hidden frames that have not been disposed
  • ensure no messages are being generated on the AWT queue (i.e. set a breakpoint in the EventQueue.)
  • otherwise look at the stack frame for these threads and see what they are busy doing
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!