Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2004

Tip: Looking for answers? Try searching our database.

JPopupMenu location

Thread view: 
staff - 26 Mar 2004 12:36 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.