aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes closeable frame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "closeable frame" Watch "closeable frame" New topic
Author

closeable frame

abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130



this frame on pressing close(X) button on title bar gets disappear but how can we make it closeable though coding
manually we use ctrl+c
Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

Well, you could just set visibility to false. In this case you really don't close the window, you just make it invisible.
There are other options but I think calling dispose() is will do the trick.

You can read more:Stackoverflow - How to close a java swing application from the code


Please correct my english.
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
in my poinion

System.exit(0);

will work .. but to implement it ???
Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

abhay jain wrote:
System.exit(0);

Daniel Spiewak from Stackoverflow has said: Crude, but effective.
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
ok .. implemented thanks a lot



waiting for more opinions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

n.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) to exit, or n.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE) to only close the frame, letting the JVM exit automatically if it's the last window and there are no other threads active.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
thanks Rob Spoor

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

You're welcome.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
EXIT_ON_CLOSE and System.exit(0) can be hazardous if there is anything else going on, for example writing to a file in a different thread. That might terminate the other thread, too, leaving the file incomplete or corrupt. Dispose would be better; the JVM will continue to run until the file writing is completed and the other thread terminates.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: closeable frame