Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4599655

setVisible(false) on iconified JDialog => Ghost JDialog

XMLWordPrintable

    • generic
    • generic

      Name: ddT132432 Date: 12/12/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      1) First you dcreate a JFrame 'frame1'
      2) Than you create a JDialog 'dialog1' (Its parent is frame1 and not modal)
      3)Than you create a second JFrame 'frame2' which has a reference on 'dialog1'
      4) You iconify 'frame1' with 'dialog1'
      5) Than you do a dialog1.setVisible(false) in 'frame2'

      Than you deiconify 'frame1'... 'dialog1' is still there! Moreover, you can't
      destroy (close) 'dialog1'... here is your Ghost JDialog!

      -----------------------------------------------------------
      Code sample:
      -----------------------------------------------------------
      import javax.swing.*;
      import java.awt.*;

      public class FrameTest extends JFrame {
        JButton jButton1 = new JButton();

        public FrameTest() {
          super("Frame 1");
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
        }
        public static void main(String[] args) {
          FrameTest frameTest1 = new FrameTest();
          frameTest1.setVisible(true);
        }
        private void jbInit() throws Exception {
          jButton1.setText("jButton1");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              jButton1_actionPerformed(e);
            }
          });
          this.getContentPane().add(jButton1, BorderLayout.CENTER);
        }

        void jButton1_actionPerformed(ActionEvent e) {
          JDialog dialog = new JDialog(this, "test dialog", false);
          dialog.pack();
          dialog.setVisible(true);
          Frametest2 frame = new Frametest2(dialog);
          frame.pack();
          frame.setVisible(true);

        }
      }
      ----------------------------------------------------------------
      import javax.swing.*;
      import java.awt.*;

      public class Frametest2 extends JFrame {
        JButton jButton1 = new JButton();
        JDialog dialog = null;

        public Frametest2(JDialog dialog) {
          super("2d frame");
          try {
            jbInit();
          }
          catch(Exception e) {
            e.printStackTrace();
          }
          this.dialog = dialog;
        }
        private void jbInit() throws Exception {
          jButton1.setText("jButton1");
          jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
              jButton1_actionPerformed(e);
            }
          });
          this.getContentPane().add(jButton1, BorderLayout.CENTER);
        }

        void jButton1_actionPerformed(ActionEvent e) {
          dialog.setVisible(false);
        }
      }
      -------------------------------------------------------------
      Run FrameTest... and let's go!

      Webbugs review <----------
      This behavior was not expieranced when using 1.3.1,1.3.1_01,1.4beta3,
      the latest build of 1.4-rc-b89 on Solaris 8.

      This bug is however reproducable on Windows NT and 2K with all versions
      of the JDK from 1.3.1 to 1.4-rc-b89.
      (Review ID: 137255)
      ======================================================================

            vbaranovsunw Vyacheslav Baranov (Inactive)
            ddressersunw Daniel Dresser (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: