SIngle-click on JButton registers multiple times - why?

T

Todd

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
 
A

Andrew Thompson

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
 
T

Todd

Todd wrote:

..


What GUI?*


* 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,

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
 
A

Andrew Thompson

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
 
T

Todd

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
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top