mouseClicked vs. mousePressed on Apple vs. Windows

M

Mike Dahmus

I'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.

Originally, our QA person asserted that it was busted because she was
clicking (and moving the mouse > 10 pixels) and it wasn't getting
"toggled" (this was on Windows). I won the battle there by saying
"don't move it 10 pixels; that's a drag, not a click". (after
debugging and figuring out that if you moved the mouse more than
approximately that much, the mouseClicked never came in).

However, she now claims that on Apple (OSX) that the button fails to
toggle if you move the mouse even one pixel while pressing the button.
(i.e. if you are not perfectly still while clicking).

Obviously this would be a different story. I don't have immediate
access to an Apple machine, so was wondering if anybody else had seen
this behavior. When I worked on the AWT on OS/2 at IBM, it was fairly
clear that the mouse events were determined based on native operating
system events (i.e. when Windows says it is a click, we'll say it is a
click). Don't know if that's true now or not, since I haven't seen the
code since Java 1.1.8.
 
F

Fred L. Kleinschmidt

Mike said:
I'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.

Originally, our QA person asserted that it was busted because she was
clicking (and moving the mouse > 10 pixels) and it wasn't getting
"toggled" (this was on Windows). I won the battle there by saying
"don't move it 10 pixels; that's a drag, not a click". (after
debugging and figuring out that if you moved the mouse more than
approximately that much, the mouseClicked never came in).

However, she now claims that on Apple (OSX) that the button fails to
toggle if you move the mouse even one pixel while pressing the button.
(i.e. if you are not perfectly still while clicking).

Obviously this would be a different story. I don't have immediate
access to an Apple machine, so was wondering if anybody else had seen
this behavior. When I worked on the AWT on OS/2 at IBM, it was fairly
clear that the mouse events were determined based on native operating
system events (i.e. when Windows says it is a click, we'll say it is a
click). Don't know if that's true now or not, since I haven't seen the
code since Java 1.1.8.

A click is usually defined as pressing and releasing the mouse button
without moving in between.

I never use the MouseClick, since it is very difficult for some people
to do this.

This is especially true for buttons (push buttons or toggle buttons) -
you usually want to give the user the opportunity to change her mind
after pressing the button, so she could move away from the button before
the release and thus have no action taken.
 
J

John C. Bollinger

Mike said:
I'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.

You might not want to be hooking mouse events of any kind. Would it not
be sufficient to extend javax.swing.AbstractButton or
javax.swing.JToggleButton and hook action events? Or is that what
you're doing now that isn't working well? Similar cross-platform
behavior will be easier to achieve the higher the level at which you
work. Indeed, depending on your exact requirements you might do even
better by using a concrete JToggleButton implementation and installing a
custom look and feel.


John Bollinger
(e-mail address removed)
 
M

Mike Dahmus

I'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.

Originally, our QA person asserted that it was busted because she was
clicking (and moving the mouse > 10 pixels) and it wasn't getting
"toggled" (this was on Windows). I won the battle there by saying
"don't move it 10 pixels; that's a drag, not a click". (after
debugging and figuring out that if you moved the mouse more than
approximately that much, the mouseClicked never came in).

However, she now claims that on Apple (OSX) that the button fails to
toggle if you move the mouse even one pixel while pressing the button.
(i.e. if you are not perfectly still while clicking).

Obviously this would be a different story. I don't have immediate
access to an Apple machine, so was wondering if anybody else had seen
this behavior. When I worked on the AWT on OS/2 at IBM, it was fairly
clear that the mouse events were determined based on native operating
system events (i.e. when Windows says it is a click, we'll say it is a
click). Don't know if that's true now or not, since I haven't seen the
code since Java 1.1.8.

Following up:

A colleague of mine wrote a simple test case and confirmed the
different behavior on Apple vs. Windows. Ended up rewriting my code to
do something similar to what AbstractButton does (remember where the
mousePressed happened; then on mouseExited or mouseReleased, process
accordingly).
 

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,054
Latest member
TrimKetoBoost

Latest Threads

Top