• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

closeable frame

 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



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
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my poinion

System.exit(0);

will work .. but to implement it ???
 
Kristjan Toots
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abhay jain wrote:
System.exit(0);

Daniel Spiewak from Stackoverflow has said: Crude, but effective.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok .. implemented thanks a lot



waiting for more opinions
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
abhay jain
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Rob Spoor

 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic