Results 1 to 4 of 4
  1. #1
    Jary316 is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default How to detect double click with a JFrame

    Hello everyone,

    I was able to find a solution to my problem but I have one issue: my current code thinks the first click of a double click is a normal click. I do not know how to solve this.

    Java Code:
    	@Override
    	public void mousePressed(MouseEvent e) {
    		if (!doubleClicked) {
    			if (e.getClickCount() == 2) { .... }
    			else { ... }
    		}
    	}
    The else bracket gets executed when the user is making a double click, on the first click, and it should not. Does anyone has any idea how I can fix this please?
    Thank you very much.

  2. #2
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default cross posted !!!

    Cross posted at Sun's forums:
    New To Java - How to detect double click with a JFrame

    You're not supposed to do that... it irritates people and is a good way to not get help.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    You have the right idea, checking the click count. If the click count is not two, don't do anything. One way to handle this is to check for that condition first in your handler. If the click count is not two, return.

  4. #4
    Jary316 is offline Member
    Join Date
    Dec 2008
    Posts
    8
    Rep Power
    0

    Default

    I am sorry CJSLMAN.

    The thing is that I need a different action to be executed for a single click, but it gets executed on the first click of a double click.

Similar Threads

  1. Executing a jar double-click style in Linux
    By goodwillwins in forum AWT / Swing
    Replies: 24
    Last Post: 03-19-2011, 04:56 AM
  2. Double click radio button
    By mandragora in forum AWT / Swing
    Replies: 11
    Last Post: 11-10-2008, 11:06 AM
  3. Detect when the user scrolls a text control
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-25-2008, 02:21 PM
  4. Detect loading of ImageIcon from URL?
    By barkster in forum Java Applets
    Replies: 1
    Last Post: 01-29-2008, 07:04 PM
  5. Detect TimeOut in a HttpURL Connection
    By Ed in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 04:29 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
  •