?
Solved

User "X" button to close a dialog

Posted on 2003-03-25
8
Medium Priority
?
169 Views
Last Modified: 2008-03-06
Hi, all

I have created a dialog. It will be opened when I click on an applet. But when I click on the "X" button on the upper right corner, it can't be closed. How can I make it works? Thanks.
0
Comment
Question by:CodeLover
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8203636
 Can you post your code?
0
 
LVL 2

Expert Comment

by:haydes007
ID: 8203883
Why not just use a close button with an ActionListener added to it? This way all that needs to be in the ActionListener method is this.setVisable(false);. If you do it the other way, there are like 6(not sure exactly) methods that have to be written, even if you dont use them all, for your code to properly compile and work the way you want it to.
0
 
LVL 9

Accepted Solution

by:
yongsing earned 200 total points
ID: 8207516
You need to add a window listener to it:

this.addWindowListener(
  new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      setVisible(false);
      dispose();
    }
  }
);

"this" is the dialog instance.
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 35

Expert Comment

by:girionis
ID: 8209031
 If it is a JDialoh you used you should'nt need to add a window listener in order to close it. The following would do just as fine:

public static void main(String [] arguments)
     {
          JDialog myDialog = new JDialog((JFrame)null, true);
          myDialog.show();
          myDialog.dispose();
     }
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8209064
If it's an AWT Dialog, I think you need the window listener to close it.
0
 

Author Comment

by:CodeLover
ID: 8247878
Thanks, all

yongsing, when I try to put the window listener in the constructor or somewhere else, the dialog can't be opened. Could you please give me some sample codes for it? Thanks.
0
 
LVL 9

Expert Comment

by:yongsing
ID: 8250224
You mean the dialog can't be opened after you put the window listener to it? You should show us your code.
0
 

Author Comment

by:CodeLover
ID: 8272149
Thanks, all

It works now. :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question