JDK-4511106 : First Call To JWindow.pack() gives inconsistent size(height rtns one Pixel less)
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-10-04
  • Updated: 2004-11-16
  • Resolved: 2004-11-16
Related Reports
Duplicate :  
Description
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

Comments
EVALUATION Reproducable on Merlin B82 Win32. ###@###.### 2001-10-08 Name: osR10079 Date: 10/28/2002 The cause of this problem is that WWindowPeer.insets() returns -1 as top inset equals when size of Window is (0, 0). I think this is because incorrect code in AwtWindow::UpdateInsets(): ::GetWindowRect(GetHWnd(), &outside); .... skipped ... /* Update our inset member */ if (outside.right - outside.left > 0 && outside.bottom - outside.top > 0) { ::MapWindowPoints(GetHWnd(), 0, (LPPOINT)&inside, 2); m_insets.top = inside.top - outside.top; m_insets.bottom = outside.bottom - inside.bottom + extraBottomInsets; m_insets.left = inside.left - outside.left; m_insets.right = outside.right - inside.right; } else { m_insets.top = -1; } ###@###.### 2002-10-28 ======================================================================
28-10-2002