JDK-4092034 : Window.getLocation() returns incorrect values after resize
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.4,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: generic,sparc
  • Submitted: 1997-11-11
  • Updated: 1998-02-04
  • Resolved: 1998-02-04
Related Reports
Duplicate :  
Duplicate :  
Description

Name: bk70084			Date: 11/11/97


Running Solaris 2.5.1 with the standard CDE window manager on Sparc.

When a Frame (or probably any Window) is resized by dragging the top or left edges of the window 
only (or the top left corner), the value of Window.getLocation() does not change to reflect the new 
position, although getSize() is updated. Dragging the right/bottom edges (correctly) does not change 
the value of getLocation(). Moving the window (correctly) does change the value of getLocation().

On WindowsNT x86, JDK1.1.4 at least, this bug is not present.

Also, when moving the Frame to the position on screen that the window manager reports as (0,0), 
the getLocation() function returns x=1,y=0 instead of x=0,y=0.

I'm trying to write a tool-tip class for Java. The actual tooltip itself is a Window and so needs to be 
placed on screen using absolute screen co-ordinates. I would like the tooltip to appear just below 
the component it is a tip for. To do this, I need to know the absolute screen co-ordinates of the 
given component. I find this by iterating over getParent() from the component upto its enclosing 
Window, adding component.getLocation().x to the x co-ordinate for each component and likewise 
for the y co-ordinates.

On WinNT this works fine. However, on Solaris/Motif, the getLocation() of the Window returns 
co-ordinates for the top-left corner of the window-manager's border, rather than the top-left 
corner of the client area, but the getLocation() for the Window's child is measured relative to the 
top left corner of the client area. This means that under Solaris/Motif, all tooltips appear too 
left/high by an equal amount to the thickness of the window manager's window border.

This often means that the tooltip covers part of the component, often where the mouse is, causing 
the component to lose focus and hide the tooltip!

The first bug mentioned above causes tooltips to appear in a location too far right/down, since they 
appear where they should have appeared for the component's position before the window resize.

Source code (BugTest1.java):

import java.awt.* ;
import java.awt.event.* ;

class BugTest1 extends Frame implements ComponentListener
{
   BugTest1()
   {
      add( new Button( "Space filler" ) ) ;
      pack() ;
      addComponentListener( this ) ;
   }

   public void componentResized( ComponentEvent ev )
   {
      System.out.println( "Window resized" ) ;
      System.out.println( "   Pos.: " + getLocation() ) ;
      System.out.println( "   Size: " + getSize() ) ;
   }

   public void componentMoved( ComponentEvent ev )
   {
      System.out.println( "Window moved" ) ;
      System.out.println( "   Pos.: " + getLocation() ) ;
      System.out.println( "   Size: " + getSize() ) ;
   }

   public void componentShown( ComponentEvent ev )
   {
      System.out.println( "Window shown" ) ;
   }

   public void componentHidden( ComponentEvent ev )
   {
      System.out.println( "Window hidden" ) ;
   }

   public static void main( String args[] )
   {
      BugTest1 bt1 = new BugTest1() ;
      bt1.show() ;
   }
}
(Review ID: 19471)
======================================================================

Comments
WORK AROUND Name: bk70084 Date: 11/11/97 None known that aren't hacks! ======================================================================
11-06-2004