Hi, Ajit.
Is this bug a regression of JDK-7088744 or JDK-8049069, or it works this
way in jdk6 as well?
I guess the code in jdk6 was something like this:
public static boolean isLeftMouseButton(MouseEvent anEvent) {
return ((anEvent.getModifiers() & InputEvent.BUTTON1_MASK) != 0);
}
On 24.03.16 12:55, Ajit Ghaisas wrote:
Hi,
Bug : https://bugs.openjdk.java.net/browse/JDK-8049069
Issue : A JButton which is pressed using left mouse button gets released if
right mouse button is pressed and released.
Root cause :
---------------
In file BasicButtonListener.java, mousePressed() and mouseReleased() methods
check whether the event is from left mouse button.
This check is done using ---- if (SwingUtilities.isLeftMouseButton(e) )
This method returns true if left mouse button is down OR event is from left
mouse button.
SwingUtilities.isLeftMouseButton() returns true if it is called for right mouse
event while holding left button down. This causes mouseReleased() method to
release pressed JButton.
Alternatives considered :
-----------------------------
1. Modifying SwingUtilities.isLeftMouseButton() method to only test for whether
the event is from left mouse button only
2. Modifying mousePressed() and mouseReleased() methods to check for whether
the event is from left mouse button using argument passed to them.
Option 1 will break the code wherever SwingUtilities.isLeftMouseButton() is
used to test for left mouse button down.
File history revealed that the mouse button down condition is added to fix
another bug.
Hence, option 2 is chosen as it is safe and intuitive.
I have also added a test. It passes on Windows, Linux and Mac.
Test mentioned in comment on the bug also passed.
Please review the webrev :
http://cr.openjdk.java.net/~aghaisas/8049069/webrev.00/
Regards,
Ajit
--
Best regards, Sergey.