Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I set up a mouse listener to close a popup window?

Status
Not open for further replies.

jeremytaffy

Technical User
Sep 6, 2001
75
US
I have a pop-up JOptionPane that I am using to confirm a selection. However, I replaced the default buttons with custom JButtons. I added listeners to these buttons to do a desired activity. One of the buttons I want to use is a cancel button. I only want to close the pop-up window, not the whole program. I have this code snippet, which I know closes the whole program. How can I make it so it only closes the popup?? Thanks!

cancelbutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0); <<<---??????
 
the window class has a dispose() method which i believe closes the window that calls it.
--Derek

&quot;Fear not the storm for this is where we grow strong.&quot;
 
well if you are running this code in a class that is a subclass of window class, you can just use:

Code:
this.dispose();

are you? --Derek

&quot;Fear not the storm for this is where we grow strong.&quot;
 
One question? Which method of JOptionPane are you using to create your pop up? I'm quite new to swing, but have plently of experience with the AWT. If you are using createDialog then you have a JDialog so you can also call hide() on it, thus hiding it from view (it inherits from java.awt.Dialog which inherits from java.awt.Window). You either will wish to call createDialog again or I think add some type of FocusListener if you wish to show the Window again, but in it's original state without your previous data.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top