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

NullPointerException in JOptionPane showInternalMessageDialog

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • client-libs
    • beta2
    • x86
    • linux



      Name: nt126004 Date: 08/01/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)

      Hi,

      I noticed this problem in a program I was writing. I wanted a JOptionPane
      dialogue box to appear when the application is first opened. However, I created
      the dialogue box at the end of the constructor and got weird results. The
      following example demonstrates what I saw.


      What you'll see:
      ---------------

      1. The code compiles and runs.
      2. On standard output, the size of the frame is reported correctly, though it is
      not yet visible.
      3. The first message appears centered around the top-left corner of the window,
      instead of in the middle of the frame. Click on OK (still visible) to continue.
      4. The second dialogue box appears correctly centered in the frame.

      My question:
      -----------

      Obviously, there is a problem with JDesktopPane having zero size before it is
      made visible, even though it is part of a frame that has a non-zero size. So,
      why isn't JDesktopPane resized before the frame is visible?



      /** begin source code **/

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


      public class IsThisABug {


      public static void main (String[] args) {

      // make a frame
      JFrame frame = new JFrame ("is this a bug?");
      frame.setSize (512, 384);
      frame.addWindowListener (new WindowAdapter () {
      public void windowClosing (WindowEvent we) {
      System.exit (0);
      }
      } );

      // make a virtual desktop
      JDesktopPane desktop = new JDesktopPane ();
      frame.setContentPane (desktop);
      System.out.println (frame.getSize ());

      // add a dialogue box before the window is visible
      JOptionPane.showInternalMessageDialog
      (desktop, "I am not in the middle of the screen");
      frame.show ();
      JOptionPane.showInternalMessageDialog
      (desktop, "Now I am in the middle of the screen");
      }
      }

      /** end source code **/



      (Review ID: 128318)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: