yep, you need to look into using the getX and getY methods of the MouseEvent class. These will give you pixel positions and you can check them against the known space filled up by your image:
testIcon1.addMouseListener(
new MouseAdapter(){
public void mousePressed(MouseEvent e)
{
triggerMenu(e);
}
public void mouseReleased(MouseEvent e)
{
triggerMenu(e);
}
public void triggerMenu(MouseEvent e)
{
popupMenu.show(e.getComponent(), e.getX(), e.getY());
}
}
);
This is an inner class attached to a button I have set up that uses the X and Y coordinates to display a pop-up menu at the point clicked by the mouse. But it can easily be adapted to just get the coordinates for your own use.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.