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

Code after setVisible(true) is not executed after hiding this dialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6
    • client-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_03"
      Java(TM) SE Runtime Environment (build 1.6.0_03-b05)
      Java HotSpot(TM) Client VM (build 1.6.0_03-b05, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Hello,

      i think that i have found an bug in the New Modality API. When setting a modal
      dialog visible with setVisible(true) the execution of the code is stoped here
      until the modal dialog is hidden with setVisible(false). After setVisible(false) the
      code after setVisible(true) will be executed.
      if you now set two DOCUMENT_MODAL dialogs with two different owners visible
      then the execution of the code correctly stops in both setVisible(true) lines.
      Now if you hide the dialog which was show first then the code after
      setVisible(true) of the first dialog is not executed until the second dialog is
      hidden, too.

      I have written an example, look in Steps to Reproduce.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Code:

      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;

      public class BugReportModal {
        JFrame frame1 = new JFrame("frame1");
        JButton button1 = new JButton("button1");
        JDialog dialog1 = new JDialog(frame1,"dialog1",true);

        JFrame frame2 = new JFrame("frame2");
        JButton button2 = new JButton("button2");
        JDialog dialog2 = new JDialog(frame2,"dialog2",true);

        public BugReportModal() {
          frame1.setSize(150,50);
          frame1.setLocation(0,0);
          frame1.getContentPane().add(button1);

          button1.addActionListener(new ListenerButton1());

          dialog1.setSize(150,50);
          dialog1.setLocation(0,70);
          dialog1.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);

          frame2.setSize(150,50);
          frame2.setLocation(170,0);
          frame2.getContentPane().add(button2);

          button2.addActionListener(new ListenerButton2());

          dialog2.setSize(150,50);
          dialog2.setLocation(170,70);
          dialog2.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
        }


        public static void main(String[] args) {
          BugReportModal bugReportModal = new BugReportModal();
          bugReportModal.frame1.setVisible(true);
          bugReportModal.frame2.setVisible(true);
        }

        private class ListenerButton1 implements ActionListener {
          public void actionPerformed(ActionEvent actionEvent) {
            dialog1.setVisible(true);
            System.out.println("Modal Dialog1 closed.");
          }
        }

        private class ListenerButton2 implements ActionListener {
          public void actionPerformed(ActionEvent actionEvent) {
            dialog2.setVisible(true);
            System.out.println("Modal Dialog2 closed.");
          }
        }
      }

      1. Compile the Code above
      2. Execute it
      3. frame1 and frame2 are shown
      4. press button1.
            - dialog1 was shown.
            - frame1 is no longer accessible.
            - executon of the code after dialog1.setVisible(true) is stoped
            - frame2 is still accessible.
      5. press button2.
            - dialog2 was shown.
            - frame2 is no longer accessible.
            - executon of the code after dialog2.setVisible(true) is stoped
      6. now close dialog1.
            - BUG HERE
            - after hiding dialog1 the code after dialog1.setVisible(true) have to be
                executed. but, look on your console,
                System.out.println("Modal Dialog1 closed.") was NOT executed.
            - frame1 is accessible again.
      7. now close dialog2.
            - after hiding dialog2 the code after dialog2.setVisible(true) and
                dialog2.setVisible(true) is executed. (the two System.out...)
            - frame2 is accessible again.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionListener;
      import java.awt.event.ActionEvent;

      public class BugReportModal {
        JFrame frame1 = new JFrame("frame1");
        JButton button1 = new JButton("button1");
        JDialog dialog1 = new JDialog(frame1,"dialog1",true);

        JFrame frame2 = new JFrame("frame2");
        JButton button2 = new JButton("button2");
        JDialog dialog2 = new JDialog(frame2,"dialog2",true);

        public BugReportModal() {
          frame1.setSize(150,50);
          frame1.setLocation(0,0);
          frame1.getContentPane().add(button1);

          button1.addActionListener(new ListenerButton1());

          dialog1.setSize(150,50);
          dialog1.setLocation(0,70);
          dialog1.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);

          frame2.setSize(150,50);
          frame2.setLocation(170,0);
          frame2.getContentPane().add(button2);

          button2.addActionListener(new ListenerButton2());

          dialog2.setSize(150,50);
          dialog2.setLocation(170,70);
          dialog2.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
        }


        public static void main(String[] args) {
          BugReportModal bugReportModal = new BugReportModal();
          bugReportModal.frame1.setVisible(true);
          bugReportModal.frame2.setVisible(true);
        }

        private class ListenerButton1 implements ActionListener {
          public void actionPerformed(ActionEvent actionEvent) {
            dialog1.setVisible(true);
            System.out.println("Modal Dialog1 closed.");
          }
        }

        private class ListenerButton2 implements ActionListener {
          public void actionPerformed(ActionEvent actionEvent) {
            dialog2.setVisible(true);
            System.out.println("Modal Dialog2 closed.");
          }
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No Workaround found.

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: