Hello,
I am showing JPopupMenu by JPopupMenu.show(invoker, x, y), and as x and y i
pass mouseEvent coordinates. But next when in action I obtain this
JPopupMenu and call JPopupMenu.getLocation() I receive Point(0, 0).
Anybody knows how to obtain correct location of JPopupMenu?
Regards
amorfis
Christian Kaufhold - 26 Mar 2004 18:42 GMT
> I am showing JPopupMenu by JPopupMenu.show(invoker, x, y), and as x and y i
> pass mouseEvent coordinates. But next when in action I obtain this
> JPopupMenu and call JPopupMenu.getLocation() I receive Point(0, 0).
>
> Anybody knows how to obtain correct location of JPopupMenu?
Component locations are always in the coordinate system of the parent.
Maybe you want getLocationOnScreen, or see SwingUtilities for conver-
sion of locations between different component coordinate systems.
Christian
staff - 01 Apr 2004 09:17 GMT
>> I am showing JPopupMenu by JPopupMenu.show(invoker, x, y), and as x and y
>> i pass mouseEvent coordinates. But next when in action I obtain this
[quoted text clipped - 6 lines]
> Maybe you want getLocationOnScreen, or see SwingUtilities for conver-
> sion of locations between different component coordinate systems.
No, problem is it does not work at all. I always get Point(0, 0), wherever
on the parent JPopupMenu appears. It is not correct, is it?
regards
Pawel Stawicki
Christian Kaufhold - 01 Apr 2004 12:10 GMT
>>> I am showing JPopupMenu by JPopupMenu.show(invoker, x, y), and as x and y
>>> i pass mouseEvent coordinates. But next when in action I obtain this
[quoted text clipped - 9 lines]
> No, problem is it does not work at all. I always get Point(0, 0), wherever
> on the parent JPopupMenu appears. It is not correct, is it?
Yes, it is. In the coordinate system of its parent, the JPopupMenu is at
coordinates (0, 0), i.e. in the upper left corner.
Christian
Filip Larsen - 13 Apr 2004 11:05 GMT
> I am showing JPopupMenu by JPopupMenu.show(invoker, x, y), and as x and y i
> pass mouseEvent coordinates. But next when in action I obtain this
> JPopupMenu and call JPopupMenu.getLocation() I receive Point(0, 0).
This has been reported as bug 4527633 (see
http://developer.java.sun.com/developer/bugParade/bugs/4527633.html).
> Anybody knows how to obtain correct location of JPopupMenu?
If you use JPopupMenu.show(Component,int,int) to pop up the menu you
can use the requested popup location instead. I use a general mouse
listener that stores this point in a client property on the popup menu
just before it calls show, but you can of course store the point in
any way you like.
Note that the requested popup point is not the same as the location of
the menu, as the actual popup position is adjusted when you get close
to the component bounds. For my application I actually need the point
where the user clicked and not the location of the menu, so this is
better. If you really need the location of the menu there might be
another work-around, but I am not aware of it.
Regards,

Signature
Filip Larsen