java swing close window without exiting app

后端 未结 8 1458
慢半拍i
慢半拍i 2021-01-12 04:31

I have a little frame where I ask user & password. This frame will be opened clicking over a button in a main window.

Then I have two buttons: ok and cancel.

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 05:25

    You can call setVisible(false) on the frame.

    You might also want to call setDefaultCloseOperation on the frame passing in HIDE_ON_CLOSE (info here: http://java.sun.com/javase/6/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation%28int%29). That will prevent the app from going away if they user hits the "X" on the JFrame to close it.

提交回复
热议问题