i have a frame that instantiates another frame but i don't want to use the close(x) button on the instantiated frame., so i created a button. how do i code that this button can be used to close the instantiated frame without quitting the JVM.
相关问题
- JTextField resizing upon minimize
- call paintcomponent for a jpanel in jframe
- How to avoid JFrame EXIT_ON_CLOSE operation to exi
- What is a good way to Organize multiple JPanel'
- Changing the Panels of a JFrame “disable” the inpu
相关文章
- How can I set the insets of a JFrame?
- Why aren't my coordinates matching my JFrame s
- how do i clear my frame screen in java?
- Two Different Panels in One Frame - Java
- Why Timer does not work if we do not generate a wi
- How to Remove JFrame Border as to Let an Image Tou
- Transparent JFrame background
- How to open a new window by clicking a button
You could try the setVisible() or dispose() functions
For your main class...
For your first frame class...
For the instantiated frame...
You could use
setVisible(false)
in order to just hide the instantiated JFrame from viewI agree with Tom, I think that in the code you wrote down:
EXIT_ON_CLOSE
means that it will exit the application completely.You can close the window by clicking on its X button by using:
Here is a sample code:
Having your own close button is weird UI and should be avoided.
To get rid of a frame when your own button is clicked you can just do:
or
if you want to get rid of it completely.
On frames you don't want to exit the JVM on the close button being clicked specify:
or
Depending on which of the behaviour you want.
Use this:
Im not sure if im right but you could call
dispose()
. The javadoc suggests you can reopen it though usingshow()
.