How to close a jframe without closing the main program

后端 未结 9 1839
天涯浪人
天涯浪人 2020-12-06 11:06

I\'m creating a program to keep track of a list of DVD\'s. On the main page I have set up 2 JButtons. When the user clicks the one that says new, a new JFrame from another c

相关标签:
9条回答
  • 2020-12-06 11:32

    If you just hide the program, using HIDE_ON_CLOSE or set.Visible(false), that is not a very good choice, because if you do something larger with more frames, the hidden frames will still be running, slowing down computer performance. The way, as other have said, is instead of using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);, which will terminate the program when you click "X, closing all of the frames, use the following:

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
    0 讨论(0)
  • 2020-12-06 11:34

    Try putting this.dispose(); inside the cancel button method.

    0 讨论(0)
  • 2020-12-06 11:38

    To hide the window without it actually closing the program, do:

    f.setVisible(false);
    
    0 讨论(0)
提交回复
热议问题