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

Tip: Looking for answers? Try searching our database.

How to retrieve the position of a given JPopupMenu

Thread view: 
Ralf Müller - 09 Mar 2005 21:44 GMT
Hallo,
I have the problem that I have a JPopupMenu object generate somewhere.
The lines of code generating and showing the menu shall not be changed.
I'd like to know the position of the the menu only be retrieving it from
 its reference. Well, the JFrame may be also be known.
Is it possible to solve this problem?

For a better understanding of my problem here is a an example:

import javax.swing.*;

public final class MyFrame extends JFrame
{
    public JPopupMenu generate()
    {
        // This method my not be changed by anyone.
        JPopupMenu men = new JPopupMenu();
                men.add( "hallo" );
                men.add( "world" );
                men.show( this, 100, 100 );
        return men;
    }

    public void myProblemMethod()
    {
        JPopupMenu menu = generate();

        // How can I implement the method below?
        // Whatever I tried returns anything but 100,100
        System.out.println(
            menu.tell_me_where_I_reside_on_the_screen());
    }
   

    public static void main ( String[] args )
    {
        MyFrame frame = new MyFrame();
        frame.setSize( 400, 400 );
        frame.show();
        frame.myProblemMethod();
    }
}

Thank you for ideas,
Ralf
John McGrath - 10 Mar 2005 14:21 GMT
> I have the problem that I have a JPopupMenu object generate somewhere.
> The lines of code generating and showing the menu shall not be changed.
> I'd like to know the position of the the menu only be retrieving it from
> its reference. Well, the JFrame may be also be known.

menu.getLocationOnScreen();

Signature

Regards,

John McGrath



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.