<Swing Dev> [9] JDK-8049069 : JButton incorrect behaviour on button release

Ajit Ghaisas ajit.ghaisas at oracle.com
Thu Mar 24 09:55:03 UTC 2016


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



More information about the swing-dev mailing list