-
Problem with Visiblity
Hello. I'm having a problem with the code I wrote to create a PopupBox. I have a click listener set up so that when i left click, the box appears at the mouse pointer, and on a right click, it disappears. the problem is that when the box is invisible, and the mouse is clicked, it is always drawn at location 0,0. I checked the points with a print statement, and the location reads correctly. when i click again and the event works correctly. Any ideas?
Code:
public void mouseClicked(MouseEvent arg0) {
//LEFT MOUSE BUTTON
if(arg0.getButton() == MouseEvent.BUTTON1)
{
//SET LOCATION TO MOUSE POINTER WITH OFFSETS
pb.setLocation(arg0.getPoint().x - 4, arg0.getPoint().y - 27);
//SHOW VARIABLES
System.out.println("Point: " + arg0.getPoint().x + ", " + arg0.getPoint().y);
System.out.println("Location: " + pb.getLocation().x + ", " + pb.getLocation().y);
//MAKE VISIBLE
pb.setVisible(true);
}
//RIGHT MOUSE BUTTON
if(arg0.getButton() == MouseEvent.BUTTON3)
{
//MAKE INVISIBLE
pb.setVisible(false);
}
}
Thanks.
-
try to use some like a
Code:
void this_mouseClicked(MouseEvent evt) {
if(SwingUtilities.isRightMouseButton(evt))
// Right Button Clicked
if(SwingUtilities.isLeftMouseButton(evt))
// Left Button clicked
if(SwingUtilities.isMiddleMouseButton(evt))
// Middle Button Clicked
}
-
And where do you have Quote:
e.getX() and e.getY()
here? ANd what component is for JPopupMenu here?