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

Modal dialog cannot be made non-modal

XMLWordPrintable

    • b38
    • sparc
    • solaris_2.6
    • Verified

      On JDK 1.3 under Solaris, a modal dialog does not change to non-modal when Dialog.setModal(false) is called. Instead it forever stays modal. Under win32 the Dialog successfully changes from modal to non-modal and back to modal repeatedly.

      It would make sense to not be able to change the modality of a Dialog while it is visible. However when it is NOT visible, the modality should be modifiable via the Dialog.setModal(boolean) method.


      //---------------------------ModalTest.java-----------------------------
      // Run the test case, and a Frame comes up.
      // (1) Click on the "test" button and a Dialog, initially non-modal, pops up.
      // (2) Click on the Dialog's "OK" button and it goes away.
      // (3) Click on the "test" button again, and the Dialog pops up as modal.
      // (4) Click on the Dialog's "OK" button and it goes away.
      // (5) Click on the "test" button again, and the Dialog pops up as
      // modal - it should have been non-modal.
      // (6) Every time the Dialog is shown, it is now modal even if
      // setModal(false) has been called.

      import java.awt.*;
      import java.awt.event.*;

      public class ModalTest extends Frame implements ActionListener
      {
          boolean modal = false;
          TestDialog testDialog;

          public static void main(String argv[])
          {
              ModalTest Test = new ModalTest();
          }

          public ModalTest()
          {
              setSize (200,200);
              addWindowListener(new WindowAdapter() {
                  public void windowClosing(WindowEvent evt) {
                      System.exit(0);
                  }
              });
              Button button = new Button("test");
              button.addActionListener(this);
              button.setSize(10,5);
              add(button);
              setVisible(true);
              testDialog = new TestDialog(this);
          }

          public void actionPerformed(ActionEvent e)
          {
              testDialog.setModal(modal);
              System.out.println("modal setting is now = " + modal);
              modal = !modal;
              testDialog.setVisible(true);
          }

          public class TestDialog extends Dialog implements ActionListener
          {
              protected Button okButton;

              public TestDialog(Frame parent)
              {
                  super(parent);

                  okButton = new Button("OK");
                  okButton.addActionListener(this);
                  add(okButton);

                  setLocation(400,400);
                  setSize(100,100);
              }

              public void actionPerformed(ActionEvent e)
              {
                  setVisible(false);
              }
          }
      }

            art Artem Ananiev (Inactive)
            bklocksunw Brian Klock (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: