Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

closing a modal jdialog

Thread view: 
Robert Ludewig - 16 Nov 2003 16:57 GMT
I have got a modal Jdialog (Jidalog extended class) that has a timer (wich
is a private member of that class) started. The user should be able  close
tis dialog with the close-button or with the x in the caption bar. How can I
make the dialg close? And how can I make sure the object including the timer
is not existing anymore?
Alex Molochnikov - 16 Nov 2003 17:31 GMT
> I have got a modal Jdialog (Jidalog extended class) that has a timer (wich
> is a private member of that class) started. The user should be able  close
> tis dialog with the close-button or with the x in the caption bar. How can I
> make the dialg close?

1. Pressing X on the title bar closes the dialog.

2. To close the dialog via a button, assign ActionListener to the button,
and in the ActionListener's actionPerformed(ActionEvent e) method close the
dialog:

dialog.setVisible(false), or
dialog.hide()

> And how can I make sure the object including the timer is not existing
anymore?

3. Depending on the Timer class, you should be able to do (2) either in the
actionPerformed(ActionEvent e) method (java.swingx.Timer) or in TimerTask's
run() method (java.util.Timer).

HTH

Alex Molochnikov
Gestalt Corporation
Robert Ludewig - 16 Nov 2003 18:09 GMT
> 3. Depending on the Timer class, you should be able to do (2) either in the
> actionPerformed(ActionEvent e) method (java.swingx.Timer) or in TimerTask's
> run() method (java.util.Timer).

Just doing (2) will not make sure that I killed the dialog and the timer.
i.e. ht timer keeps on running and I could re-show the dialog ....

Here the code:

public class JProgressDialog extends JDialog implements ActionListener
{
   private JLabel label;
   private int counter;
   private JProgressBar pgb;
   private Timer  t;
   public JProgressDialog (Frame owner)
   {
       super(owner, true);
       setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
       getContentPane().setLayout(new
BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
       pgb = new JProgressBar();
       label = new JLabel();
       getContentPane().add(new JButton("cancel"));
       getContentPane().add(label);
       getContentPane().add(pgb);
       t = new Timer(50,this);
       t.start();
   }

   public void actionPerformed(ActionEvent e)
   {
       System.out.println(counter++);
       if (counter < 100)
       {
            counter++;
           label.setText(new Integer(counter).toString());
            pgb.setValue(counter);
       }
       else
       {
           setVisible(false);
           //dispose();
           //t.stop();
       }
   }
}
ak - 16 Nov 2003 20:49 GMT
add WindowListener to your dialog and stop timer on windowClosed() event

> > 3. Depending on the Timer class, you should be able to do (2) either in
> the
[quoted text clipped - 45 lines]
>     }
> }
Alex Molochnikov - 17 Nov 2003 01:16 GMT
See the answer inside.

> > 3. Depending on the Timer class, you should be able to do (2) either in
> the
[quoted text clipped - 40 lines]
>         {
>             setVisible(false);

               t.stop();

>             //dispose();
>             //t.stop();
>         }
>     }
> }


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.