Results 1 to 3 of 3
  1. #1
    cfrancis is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default 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?

    Java 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.

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    try to use some like a
    Java 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 
    }

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    And where do you have
    e.getX() and e.getY()
    here? ANd what component is for JPopupMenu here?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •