File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes How to close this window? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to close this window?" Watch "How to close this window?" New topic
Author

How to close this window?

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i just dont know how to code this very simple situation: i have this first window that has a button which when clicked opens a second window;
this second window has a button that when clicked should close just this window, not the app

can anyone please help me?

thanks in advance

the working code follows


java amateur
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3099
    
  33

You can try using the "dispose()" method.


Mohamed Sanaulla | My Blog
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
mohamed sanaullah wrote:You can try using the "dispose()" method.


then i get this error message:
C:\...\CloseWindow.java:17: cannot find symbol
symbol: method dispose()
dispose(); }
^
1 error

Tool completed with exit code 1


when using it this way:
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3099
    
  33

You should be using JFrame instance to call it. Its part of Window (I think?) class which gets inherited by JFrame. Also you would have to declare your JFrame reference as final in the CloseWindow class. (final- because the variables being used in the Anonymous Inner class (your ActionListener) must be declared as final)



Sorry for not being clear the first time.
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks a lot - that worked!
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2227
    
    8


Don't you think you will have the same problem with the above statement?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3099
    
  33

Rob Camick wrote:

Don't you think you will have the same problem with the above statement?


The setDefaultCloseOperation would decide what to do with the JFrame when the user clicks on the Close button on the JFrame. I think by default it hides the Frame, but we would usually want to exit the Frame when we click on the Close button.
Suganya Sampath
Greenhorn

Joined: Feb 15, 2012
Posts: 1
I have also faced this problem.
This post has helped me to solve it.
Thank You
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to close this window?