Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: MouseDraged

  1. #1
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default MouseDraged

    why does this code execute multiple time when I start dragging the text. shouldn't it wait until I release the mouse key and then get the selected text? another problem is that it executes first time with "query=null" and then gets the text .
    public class linkListener implements MouseMotionListener{
    public void mouseDragged(MouseEvent arg0) {
     
    		//Handle text selection action.
    		query = note.getSelectedText();
     
    		System.out.println(query);
    		try {
    			displayItems();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    Last edited by nasi; April 3rd, 2010 at 11:50 PM. Reason: please use [code] tags

  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: MouseDraged

    See MouseMotionListener Interface: mouseDragged.

    If you want an event only to be sent when the mouse is pressed/released, see MouseListener Interface.

    The mousePressed() method is called whenever the mouse is pressed, then you can check for when the mouse was released using the mouseReleased() method.

  3. #3
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: MouseDraged

    I want the event to be sent after highlighting a text with mouse. (pressing the mouse, kepping it pressed, moving it, releasing) isn't it a mousedragged method?

  4. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: MouseDraged

    Mouse dragged means exactly that:

    Every time the mouse is dragged (moved with a button pressed), send an event. What you described is to only send events to your program when the mouse is pressed/released. For all your program could care, the mouse could have magically changed places after the mouse was pressed and then released and the same actions will still happen.

  5. #5
    Member
    Join Date
    Mar 2010
    Posts
    111
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Default Re: MouseDraged

    what I undrestand, is that when ever mouse is dragged the "mouseDragged(MouseEvent arg0)" method is called and only in that situation it should execute the method body which is

    query = note.getSelectedText();
     displayItems();

    which should get the highlighted text and call diplayItems.isn't it?

Tags for this Thread