-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
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)
======================================================================