How to properly hide a JFrame

穿精又带淫゛_ 提交于 2019-12-05 07:42:07
mKorbel
  1. use CardLayout

  2. if is there real reason for another popup container

  3. put both together, above two points, to use CardLayout for popup JDialog with parent to JFrame, notice after switch from one card to another could be / is required to call JDialog.pack()

  1. setVisible will cause slowdown
  2. dispose will cause slowdown
  3. System.exit will close entire JVM

Therefore, you should reuse a single JFrame or JDialog.

In the button's ActionListener, invoke frame.setVisible(false);. Then instead of creating a new frame just do frame.setVisible(true);. If you want to change the contents of the frame, there is the function frame.getContentPane().removeAll();.

Just add this: JFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE). Note: The default option for JFrame is HIDE_ON_CLOSE.

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