aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JFrame + windowClosed event is not getting fired. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame + windowClosed event is not getting fired." Watch "JFrame + windowClosed event is not getting fired." New topic
Author

JFrame + windowClosed event is not getting fired.

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Hi all,
on button click event, I'm creating the new JFrame instance for showing some Java 3D output.
But the code for windowClosed() method doesn't get executed at all,
but if I provided

for the same frame instance, then there is no problem

Note: J3DContainerFrame extends JPanel
Any pointers ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
try using the method hinted at by your sys.out.println

//public void windowClosed(WindowEvent e)
public void windowClosing(WindowEvent e)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

The windowClosed event is fired when the window has already closed. But it will not close if you allow it to close. You can do this by setting a proper default close operation. When you click the X it will fire the windowClosing event instead.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

OK, that was a silly mistake, Next time I should look more carfully in Java Docs
Thanks Michael & Rob for the quick and correct reply.

But my little knowledge of JFC forces me to ask this:
Why we need (separate) "windowClosed" event, can't we simply write all the code/logic related to "window closing/ed" thing in one method ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

Because you may want to be informed of both when the window is about to be closed (windowClosing), perhaps so you can block it, and when the window is actually closed (windowClosed), perhaps so you can do some clean-up.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

hmm, convincing.. I got it.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2171
    
    7
windowClosing is always fired.

windowClosed will be fired when you use:



I tend to use windowClosing as suggested in the Closing An Application entry.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JFrame + windowClosed event is not getting fired.