Detecting double click with MouseListener

Discussion in 'Java' started by John, Aug 31, 2004.

  1. John

    John Guest

    Jacob wrote:

    > I can detect a docuble click using the MouseListener
    > interface and inspect the event.getClickCount().
    >
    > However, at that point in time, the event has already
    > been classified as a single click (as the clickCount
    > is 1 the first time around).
    >
    > My intention is to start action A on a single click
    > and action B on a double click. With a standard setup
    > I will get action A on a single click but action A + B
    > on a double click!
    >
    > Seems like a delay is necessary in order to fully
    > classify the event. Is there a standard way to acheive
    > this?
    >
    > Thanks.
    >


    Let's say the double click listener calls the method
    handleDoubleClick(). In the single click listener, check the number of
    clicks, and if it is 2, call handleDoubleClick().

    Do NOT start buggering about with delays and things or your UI code will
    degenerate into rubbish.

    John
    John, Aug 31, 2004
    #1
    1. Advertising

  2. John

    Jacob Guest

    I can detect a docuble click using the MouseListener
    interface and inspect the event.getClickCount().

    However, at that point in time, the event has already
    been classified as a single click (as the clickCount
    is 1 the first time around).

    My intention is to start action A on a single click
    and action B on a double click. With a standard setup
    I will get action A on a single click but action A + B
    on a double click!

    Seems like a delay is necessary in order to fully
    classify the event. Is there a standard way to acheive
    this?

    Thanks.
    Jacob, Aug 31, 2004
    #2
    1. Advertising

  3. John

    staff Guest

    John wrote:

    > Jacob wrote:
    >
    >> I can detect a docuble click using the MouseListener
    >> interface and inspect the event.getClickCount().
    >>
    >> However, at that point in time, the event has already
    >> been classified as a single click (as the clickCount
    >> is 1 the first time around).
    >>
    >> My intention is to start action A on a single click
    >> and action B on a double click. With a standard setup
    >> I will get action A on a single click but action A + B
    >> on a double click!
    >>
    >> Seems like a delay is necessary in order to fully
    >> classify the event. Is there a standard way to acheive
    >> this?
    >>
    >> Thanks.
    >>

    >
    > Let's say the double click listener calls the method
    > handleDoubleClick(). In the single click listener, check the number of
    > clicks, and if it is 2, call handleDoubleClick().


    This is not a solution. When double clicking two events are generated. First
    with clickCount = 1, second with cilckCount = 2.

    Greetings
    Pawel Stawicki
    staff, Aug 31, 2004
    #3
  4. > Let's say the double click listener calls the method
    > handleDoubleClick(). In the single click listener, check the number of
    > clicks, and if it is 2, call handleDoubleClick().
    >
    > Do NOT start buggering about with delays and things or your UI code will
    > degenerate into rubbish.


    The Java versions I have worked with (Sun), there is only one
    mouseclickevent, and in the case of a double click, that event is fired
    twice, once with a clickcount of 1 and once with a clickcount of 2. At the
    time when the clickcount of 1 is present, there is no way to determine
    whether the user will click once more.

    One possible method is to select a singleclickaction which does not conflict
    with the doubleclickaction. F.ex single click->selection, double
    click->activation.

    I have had a few cases where I wanted actions that did conflict. I did not
    implement the delay, but changed the actions.

    Niels Dybdahl
    Niels Dybdahl, Aug 31, 2004
    #4
  5. John

    John Guest

    staff wrote:

    > John wrote:
    >
    >
    >>Jacob wrote:
    >>
    >>
    >>>I can detect a docuble click using the MouseListener
    >>>interface and inspect the event.getClickCount().
    >>>
    >>>However, at that point in time, the event has already
    >>>been classified as a single click (as the clickCount
    >>>is 1 the first time around).
    >>>
    >>>My intention is to start action A on a single click
    >>>and action B on a double click. With a standard setup
    >>>I will get action A on a single click but action A + B
    >>>on a double click!
    >>>
    >>>Seems like a delay is necessary in order to fully
    >>>classify the event. Is there a standard way to acheive
    >>>this?
    >>>
    >>>Thanks.
    >>>

    >>
    >>Let's say the double click listener calls the method
    >>handleDoubleClick(). In the single click listener, check the number of
    >>clicks, and if it is 2, call handleDoubleClick().

    >
    >
    > This is not a solution. When double clicking two events are generated. First
    > with clickCount = 1, second with cilckCount = 2.
    >
    > Greetings
    > Pawel Stawicki


    Ok, apologies. (and to OP).

    John
    John, Aug 31, 2004
    #5
  6. John

    Jacob Guest

    Jacob wrote:


    > I can detect a docuble click using the MouseListener
    > interface and inspect the event.getClickCount().
    >
    > However, at that point in time, the event has already
    > been classified as a single click (as the clickCount
    > is 1 the first time around).
    >
    > My intention is to start action A on a single click
    > and action B on a double click. With a standard setup
    > I will get action A on a single click but action A + B
    > on a double click!
    >
    > Seems like a delay is necessary in order to fully
    > classify the event. Is there a standard way to acheive
    > this?



    I'll try to fix this myself; In doing so I need access
    to the system click interval. How?

    Thanks!
    Jacob, Sep 1, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian J. Sayatovic
    Replies:
    1
    Views:
    5,061
    Kleopatra
    Jul 31, 2003
  2. Peter the Swede

    MouseListener and hiding components.

    Peter the Swede, Nov 19, 2003, in forum: Java
    Replies:
    0
    Views:
    345
    Peter the Swede
    Nov 19, 2003
  3. Minti
    Replies:
    2
    Views:
    458
    Ian Shef
    Feb 19, 2004
  4. Cammy

    Newbie MouseListener Problem

    Cammy, Apr 9, 2004, in forum: Java
    Replies:
    2
    Views:
    509
    Knute Johnson
    Apr 10, 2004
  5. Sydex
    Replies:
    12
    Views:
    6,486
    Victor Bazarov
    Feb 17, 2005
Loading...

Share This Page