SIngle-click on JButton registers multiple times - why?

Discussion in 'Java' started by Todd, Aug 23, 2007.

  1. Todd

    Todd Guest

    Hello all,

    I am using NetBeans 5.5.1 (can't upgrade to 6) to develop a GUI. I
    have done this many times before, but have never run across this
    issue. I don't know if it is NetBeans related, but I included which
    IDE I am using in case someone believes that it may be.

    So, as the subject says, when I single-click on a JButton in my GUI,
    the application responds as if the button had been clicked at least
    twice (sometimes more). Is there some button setting that I am
    missing? I am utterly at a loss.

    The only thing I could think of was to put a lock around the code in
    the callback, however, it seems to run so quickly that the lock is
    released almost as quickly as it is set, allowing the code to execute
    twice. BTW, the code is just a call to a method, whereas the method
    is longer and called from multiple places.

    Thanks for any insights,
    Todd
     
    Todd, Aug 23, 2007
    #1
    1. Advertising

  2. Todd wrote:
    ...
    >So, as the subject says, when I single-click on a JButton in my GUI,


    What GUI?*

    >Thanks for any insights,


    * It is probably the Java code.
    Try changing the comma at column 43 of line 147
    to a dot, and everything should be sweet.
    Failing that fix, you might try posting an SSCCE**
    of code that demonstrates this behaviour, to the
    group.

    ** <http://www.physci.org/codes/sscce.html>

    Another tip (I'm probably just about to be accused
    of rudeness, for mentioning this, but..) is to always
    repeat the main question in the body of a post, as
    some people ignore subject/title lines.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
     
    Andrew Thompson, Aug 23, 2007
    #2
    1. Advertising

  3. Todd

    Todd Guest

    On Aug 22, 10:37 pm, "Andrew Thompson" <u32984@uwe> wrote:
    > Todd wrote:
    >
    > ..
    >
    > >So, as the subject says, when I single-click on a JButton in my GUI,

    >
    > What GUI?*
    >
    > >Thanks for any insights,

    >
    > * It is probably the Java code.
    > Try changing the comma at column 43 of line 147
    > to a dot, and everything should be sweet.
    > Failing that fix, you might try posting an SSCCE**
    > of code that demonstrates this behaviour, to the
    > group.
    >
    > ** <http://www.physci.org/codes/sscce.html>
    >
    > Another tip (I'm probably just about to be accused
    > of rudeness, for mentioning this, but..) is to always
    > repeat the main question in the body of a post, as
    > some people ignore subject/title lines.
    >
    > --
    > Andrew Thompsonhttp://www.athompson.info/andrew/
    >
    > Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1


    Andrew,

    Sorry if I posted incorrectly. Since this is an intermitent problem,
    I can not develop an SSCCE that demonstrates this behaviour. I
    understand that I forgot to mention in my original post about this
    being itermitent, again apologies.

    Also, since I am new to the group (and usenet groups in general) could
    you explain a better way of re-iterating my question than how I did in
    my second paragraph?

    Thanks,
    Todd
     
    Todd, Aug 23, 2007
    #3
  4. Todd wrote:
    ...
    >Sorry if I posted incorrectly.


    No need for apologies.

    >..Since this is an intermitent problem,
    >I can not develop an SSCCE that demonstrates this behaviour.


    That is unfortunate.

    >Also, since I am new to the group (and usenet groups in general) could
    >you explain a better way of re-iterating my question than how I did in
    >my second paragraph?


    Adding 'intermitent' would have altered my initial response
    significantly (as you say, it is difficult to make an SSCCE
    of such problems).

    My first thought was that you might have added a
    MouseListener to the button by mistake, these
    events will fire on 'click', but also on 'mouse over'
    and 'mouse out'. That does not explain why the
    behaviour is intermitent though (unless the users
    are tabbing to the button usually, but intermitently
    clicking on it with the mouse!).

    The only other things I can suggest based on the
    available information are:
    - to trawl through the bug database* looking for
    anything similar.
    - to post to the specialist group for GUI matters,
    comp.lang.java.gui (though note that most
    people who read that, flagging group, also
    read c.l.j.p.). If you intend posting to c.l.j.g.,
    please mention the earlier thread here, and
    add the reason for reposting.

    * <http://bugs.sun.com/bugdatabase/index.jsp>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200708/1
     
    Andrew Thompson, Aug 23, 2007
    #4
  5. Todd

    Todd Guest

    Andrew,

    It looks like you were on the right track thinking that I may have had
    a callback improperly defined. I had created a mouse click callback
    and an action callback on the same button. I think that there may
    have been iteraction between the two, since it appears that a mouse
    click is also considered an action.

    What is odd is the intermittent nature of the issue. I would think
    that if a click is considered an action both callbacks would be
    activated.

    Todd
     
    Todd, Aug 23, 2007
    #5
  6. Todd

    Roedy Green Guest

    On Wed, 22 Aug 2007 21:24:51 -0700, Todd <>
    wrote, quoted or indirectly quoted someone who said :

    >So, as the subject says, when I single-click on a JButton in my GUI,
    >the application responds as if the button had been clicked at least
    >twice (sometimes more). Is there some button setting that I am
    >missing? I am utterly at a loss.


    Mechanically your finger micro-vibrates and hence hits the button on
    and off several times as you hit it. Dealing with the problem is
    called "debouncing". In the olden days you did it with hardware.
    Today you would do it with software to discard the fibrillations. You
    might find some adjustment in your mouse driver. Look for a "double
    click" speed adjustment. You also might try a higher quality mouse.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 23, 2007
    #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. patrick

    JButton auto click

    patrick, Apr 2, 2004, in forum: Java
    Replies:
    1
    Views:
    1,102
    Steve W. Jackson
    Apr 2, 2004
  2. Allan Bruce
    Replies:
    3
    Views:
    1,782
    Phillip Mills
    Jun 15, 2004
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,226
    Smokey Grindel
    Dec 2, 2006
  4. Replies:
    1
    Views:
    1,374
  5. Jack Steven
    Replies:
    2
    Views:
    474
    Chris Rebert
    Mar 9, 2009
Loading...

Share This Page