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 / November 2005

Tip: Looking for answers? Try searching our database.

JPopupMenu position changing

Thread view: 
Martin Buerger - 27 Nov 2005 20:18 GMT
Hello,
the situation:
a JPanel containing a JSplitPane with two JScrollPanes; one of the
JScrollPanes has a JTree, the other one a JTable in it. Each, JTree and
JTable have their own MouseListener which pops up with a certain popup menu
(add node, delete node // add attribute, delete attribute). This whole
construct is used in some other program (JFrame).
The problem: the position of the JPopupMenus isn't the same where I clicked
with the mouse (mouseevent.(getX()|getY()). I solved this partly: when I
click in the pane with the JTree the actual position of the click =

frame.getX() + mouseevent.getX(), frame.getY() + mouseevent.getY()

This works for the upper pane. For the lower one with the JTable this
doesn't work. The popup menu is always situated somewhere above the divider
of the two panes. I noticed changing the location of the divider changes
the position of the popup menu even if I click at the exact same position
on the screen without moving anything except the divider.

Well, I'm stuck with this (java version "1.5.0_04", Linux). Any suggestions?

Thank you,
Martin
Kari Ikonen - 27 Nov 2005 21:17 GMT
> ...
> frame.getX() + mouseevent.getX(), frame.getY() + mouseevent.getY()
> ...

Coordinates in the MouseEvent are relative to component receiving the event.
If coordinates are required to be converted between coordinate spaces, then
SwingUtilities.convertX() -methods can be used.

However, best fix would be just to use component receiving the mouseevent as
"invoker" for JPopup.show().

The fact that it seemed to "work" for uppper pane, is just because it's
origin happened to be at (0 0). If there would have been e.g. menubar
visible in JFrame, then popup location would have been failing also for it.

Signature

KI -- http://kari.world.dy.fi

Martin Buerger - 27 Nov 2005 21:59 GMT
> However, best fix would be just to use component receiving the mouseevent
> as "invoker" for JPopup.show().
I'm not sure if I understand you right: I have to receive the mouseevent via
another Component, thus I've to add the MouseListener to this other
Component (JFrame)? Or do you mean, JTree|JTable receive the mouseevent but
delegate it somehow(?) somewhere(?)?

Thank you,
Martin
Martin Buerger - 28 Nov 2005 21:01 GMT
> Coordinates in the MouseEvent are relative to component receiving the
> event. If coordinates are required to be converted between coordinate
> spaces, then SwingUtilities.convertX() -methods can be used.
The only way I found to solve this was to use
SwingUtilities.convertPointToScreen(). Thanks for your help.

Ciao,
Martin


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.