I have a JPopupMenu object. Its behavior depends on its coordinates. How can I get its position relatively to its parent container?
In your MouseListener
's method (mouseReleased etc.) you should receive a MouseEvent
object containing the current position. If you don't want to use those values you can try using the Component#getLocation
method, otherwise the Component#getLocationOnScreen
but it returns the absolute position, then you need to calculate the relative one.