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

JOptionPane.showInternalOptionDialog blocks after its enclosing JFrame is closed

XMLWordPrintable

    • b10
    • generic
    • generic
    • Verified

      Name: yyT116575 Date: 09/27/2001


      java version "1.3.0_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_02)
      Java HotSpot(TM) Client VM (build 1.3.0_02, mixed mode)


        Description of bug:
      ------------------

      JOptionPane.showInternalOptionDialog(...) and its ilk create internal dialogue
      boxes designed for a JDesktopPane environment, but unlike JDialog,
      JInternalFrame does not provide modal functionality - that is, it does not block
      user input to other JInternalFrame objects in the same JDesktopPane.
      This particular problem appears when an internal dialogue box appears, courtesy
      of showInternalOptionDialog(...) or another such method in JOptionPane, and the
      JFrame that contains it is closed before the dialogue is dismissed. Everything
      seems to be closed correctly, but the JOptionPane method never returns. This
      causes problems in our system when it tries to exit, with things hanging
      mysteriously and never being terminated.

      Sample source code:
      ------------------

      Compile and run the following source code. Try dismissing the dialogue box,
      which will force the system to exit. Run it again and close the window without
      dismissing the dialogue box. The JFrame will be disposed by a WindowAdapter,
      but JOptionPane.showInternalMessageDialog(Component,Object,String,int) will
      never return.

      /** begin source code **/

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


      public class IFTest extends JFrame {

        public IFTest () {
          super ("Internal Frame test");
          setSize (640, 480);
          setContentPane (new JDesktopPane ());

          // just dispose on exit (the old 1.2 way)
          addWindowListener (new WindowAdapter () {
            public void windowClosing (WindowEvent we) {
              System.out.print ("Disposing of window...");
              dispose ();
              System.out.println ("done.");
            }
          });
        }

        public static void main (String[] args) {

          // somewhere for the internal dialogue box
          IFTest iftest = new IFTest ();
          iftest.setLocation (50, 50); // cascade frame a bit
          iftest.show ();

          // show the internal dialogue box
          JOptionPane.showInternalMessageDialog (
              iftest.getContentPane(),
              "Clicking OK will exit the system.\nClose the window and the system will hang.",
              "Test", JOptionPane.INFORMATION_MESSAGE
          );

          // once that's finished, force an exit
          System.out.println ("OK");
          System.exit (0);
        }

      }

      /** end source code **/

      Suggestions:
      -----------

      The "correct" behaviour, as I see it, should be either:

        (a) closing the window should force the JOptionPane to return as if the
      dialogue box was cancelled; or

        (b) block attempts to close the window if there is an internal (and,
      eventually, modal) dialogue box in the JDesktopPane.

      Neither of these seems particularly easy to me.

      Post Scriptum:
      -------------

      This behaviour also appears in Beta 2 of the 1.4.0 Java Runtime Environment
      (java -version reports: build 1.4.0-beta2-b77, mixed mode).
      (Review ID: 132691)
      ======================================================================

            art Artem Ananiev (Inactive)
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: