• Post Reply Bookmark Topic Watch Topic
  • New Topic

(JFrame.EXIT_ON_CLOSE) programmatically.

 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Is there a way to exit a JFrame programmatically without clicking on the X In the window.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15711
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call setVisible(false) on the JFrame so that it is not visible anymore on screen. If you want to exit the application, you can call System.exit(...).
 
Nikolas Nikolaou
Ranch Hand
Posts: 101
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying
System.exit(..) Is the only thing that works for me so far but I was curious as to whether this Is a sloppy way to clear things up.
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also call dispose() on the JFrame.
 
Campbell Ritchie
Marshal
Posts: 52516
118
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But dispose() is different from System.exit();

They used to have to add listeners in AWT, rather like this:


[Edit]Moving to our GUIs forum[/edit]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!