Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Swing closing window  RSS feed

 
Lee Lares
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I have JDialog and in that JDialog I have JPanel and in that JPanel i have button and i would like to close JDialog after pressing that button. I couldn't find any informations about this. Only thing i know is how to close that JPanel with but it closes only JPanel and JDialog still stays.
 
Les Morgan
Rancher
Posts: 767
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lee,
The setVisible(false) only hides the dialog, you can see that by doing a setVisible(true) and it comes right back, you need to do a dispose() to make it close and be available to the GC.
Les
Lee Lares wrote:Hello, I have JDialog and in that JDialog I have JPanel and in that JPanel i have button and i would like to close JDialog after pressing that button. I couldn't find any informations about this. Only thing i know is how to close that JPanel with but it closes only JPanel and JDialog still stays.
 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to close JDialog after pressing that button


You need to close the dialog NOT the panel.

To access the dialog you can add the following in the ActionListener of your button:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!