Alexander Auermaa Alexander Auermaa - 6 months ago 12
Java Question

jPopupMenu displaying way-off when window of application is moved

I am having somewhat of a problem with my jPopupMenu. When I run my project, everything loads correctly, there's no errors, the popupmenu works perfectly, the popupmenu is exactly where I want it when I rightclick.

However, when I move or resize the window of my application, and then rightclick to show my popupmenu, it shows up on the other side of the screen and/or way "offcourse". The more I move my window the more "offcourse" the popupmenu gets, any ideas?

I am using this code for my rightclick

if(evt.isPopupTrigger())
{
jPopupMenu1.show(this, evt.getXOnScreen(), evt.getYOnScreen());
}


Picture:

misplaced popupmenu(?)

EDIT: I might add that the popupmenu works correctly if I have my application maximized.

Answer

In case anybody needs this...I figured it out.

The code I was using:

                                 if(evt.isPopupTrigger())
{
    jPopupMenu1.show(this, evt.getXOnScreen(), evt.getYOnScreen());
}

And the code that was needed:

                                if(evt.isPopupTrigger())
    {
        jPopup1.show(evt.getComponent(),
                       evt.getX(), evt.getY());
    }

This solved my issue with the popupmenu displaying on the other side of the screen/"offcourse".