Results 1 to 9 of 9
  1. #1
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Post removing mousemoved actionevent from buttons

    hello I have many buttons on a jframe and i would like my jframe to be the only component that triggers mouse moved method, although my buttons on the frame are registering as a component and I want to disable this.

    I have added mousemotionlistener to the frame and to no buttons.

    i do not want my buttons to the source component.

    Java Code:
    myframe.add(myjbutton);
    myframe.addmousemotionlistener();
    public void mousemoved(MouseEvent e){
    myXinteger = e.getLocation().getX();
    }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    938
    Rep Power
    2

    Default Re: removing mousemoved actionevent from buttons

    You are making no sense. If you want to track the mouse over your entire application, you probably should be looking at a glasspane. Although I really think you are solving a problem the wrong way. Care to tell us what you are trying to accomplish?
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,909
    Rep Power
    5

    Default Re: removing mousemoved actionevent from buttons

    You have the buttons literally in the JFrame, or do you have some other component (such as a JPanel) around them?

    Why don't you just post some relevant parts of your real code and not some hastily thrown together and uncompilable snippet.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: removing mousemoved actionevent from buttons

    Hi Nathan,
    can you post an SSCCE? Normally the buttons won't trigger the mouseMoved() method.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: removing mousemoved actionevent from buttons

    http://nathanscomputerknowledge.com/...onproblem2.swf

    please watch this short video

    see how im moving an image at my cursor but when my cursor is over a button it doesnt move, but when over my jframe it does.

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,909
    Rep Power
    5

    Default Re: removing mousemoved actionevent from buttons

    Yes... so your REAL question is how you ALSO receive events when the cursor is over a component inside the frame.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: removing mousemoved actionevent from buttons

    Java Code:
    class showtoolbar extends JPanel implements ActionListener, MouseListener, MouseMotionListener, FocusListener{
    Java Code:
    				parkbutton = new JButton(new ImageIcon(park));
    				parkbutton.setBounds(50, 350, 50, 50);
    				parkbutton.setBorder(emptyBorder);
    				parkbutton.setToolTipText("A park. Costs: " + parkcost);
    				add(parkbutton, BorderLayout.NORTH);
    Java Code:
    toolbar = new JFrame();
    		toolbar.addMouseListener(this);
    		toolbar.addMouseMotionListener(this);
    Java Code:
    	@Override
    	public void mouseMoved(MouseEvent e) {
    		// TODO Auto-generated method stubMouseInfo.getPointerInfo()MouseInfo.getPointerInfo().getLocation()
    		//e.
    		if (toolbar.isActive()){
    			//e.setSource(toolbar);
    			mousex = e.getPoint().getX() - mousexfix;
    			mousey = e.getPoint().getY() - mouseyfix;
    			}
    	}

  8. #8
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: removing mousemoved actionevent from buttons

    its just weird "e.getPoint()" is relative to the component which a jbutton is a component without adding a mouselistener to the button

  9. #9
    natdizzle's Avatar
    natdizzle is offline Nathan Nelson
    Join Date
    Jan 2009
    Posts
    100
    Rep Power
    0

    Default Re: removing mousemoved actionevent from buttons

    might have fixed it with

    Java Code:
    			mousex = MouseInfo.getPointerInfo().getLocation().getX() - toolbar.getX() - mousexfix;
    instead of

    Java Code:
    			mousex = MouseInfo.getPointerInfo().getLocation().getX() - mousexfix;

Similar Threads

  1. Dispatch event Mousemoved more humanlike
    By coolking in forum AWT / Swing
    Replies: 3
    Last Post: 02-03-2012, 10:36 PM
  2. Canvas and mouseMoved()
    By Zman3359 in forum AWT / Swing
    Replies: 6
    Last Post: 07-06-2011, 12:59 AM
  3. Need help finding mouseMoved on a JButton
    By corrax in forum AWT / Swing
    Replies: 2
    Last Post: 05-24-2011, 08:35 AM
  4. Removing Buttons?
    By Mass Zero in forum Java Applets
    Replies: 10
    Last Post: 10-28-2009, 03:16 PM
  5. ActionEvent example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-11-2008, 11:00 PM

Posting Permissions

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