Name: rmT116609 Date: 10/04/2001
java version "1.4.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)
The first call to JWindow.pack() after adding components returns a height
that's one pixel too small.
Call it a second time and you will get the correct size.
awt.Window has the same problem.
The program below shows the problem.
import java.awt.*;
import javax.swing.*;
public class WindowTest
{
public static void main(String[] arg)
{
JFrame frame = new JFrame("Window Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 400, 300);
frame.show();
JButton button = new JButton("A Button");
System.out.println("Preferred button size: " + button.getPreferredSize());
JWindow window = new JWindow(frame);
window.getContentPane().add(button);
window.pack();
window.setLocation(200, 200);
window.show();
System.out.println("1. Window size: " + window.getSize());
System.out.println("1. Actuall button size: " + button.getSize());
System.out.println();
window.pack();
System.out.println("2. Window size: " + window.getSize());
System.out.println("2. Actuall button size: " + button.getSize());
}
}
(Review ID: 132832)
======================================================================
###@###.### 10/26/04 10:24 GMT