JDK-8041470 : JButtons stay pressed after they have lost focus if you use the mouse wheel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u11,8,9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2014-02-19
  • Updated: 2015-09-29
  • Resolved: 2015-05-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u60Fixed 9 b70Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
1.7.0_11-b21

ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.32-5-amd64. 

A DESCRIPTION OF THE PROBLEM :
Buttons on Linux do not release their 'pressed' state if the mouse button is released away from the button after using the mouse wheel. 

From monitoring events, it seems that on Linux if you use the scroll wheel while the mouse is pressed then the mouse released event is sent to the component the mouse is over rather than the component it was pressed on.  On Windows the event goes to the component the mouse was pressed on. 

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Note that these reproduction steps require that user monitors the console as this application prints via System.out.println. 

1. Compile and run the simple UI attached. 
2. Click on the 'JButton' and hold the left mouse button down, note that the application printed via System.out.println 'Currently pressed' per an override in the button UI. 
3. Drag the mouse over another part of the UI, making sure to leave the button region. 
4. Use the mouse wheel 
5. Release the left mouse button
6. Notice the application never prints 'not pressed' as it would had you not used the mouse wheel in step #4. 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Button releases, as it does on other platforms.
ACTUAL -
Button stays pressed

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------


import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.FlowLayout;
import java.awt.Graphics;

public class TestButton {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {

                /// Configure a JFrame with a JButton, with 'button pressed state' tracking.
                JFrame frame = new JFrame();
                frame.setLayout(new FlowLayout());

                final JButton jButton = new JButton("JButton");

                // Install UI as one solution to track 'button pressed' and 'button released' states.
                jButton.setUI(new BasicButtonUI() {
                    @Override
                    public void paint(Graphics g, JComponent c) {
                        super.paint(g, c);

                        if (jButton.getModel().isPressed()) {
                            System.out.println("Currently pressed");
                        } else {
                            System.out.println("Not pressed");

                        }
                    }
                });

                frame.add(jButton);

                frame.setVisible(true);
                frame.pack();
            }
        });
    }
}

---------- END SOURCE ----------


Comments
XWindow.getModifiers():605 //exclude wheel buttons from adding their numbers as modifiers if (!wheel_mouse) { modifiers |= InputEvent.getMaskForButton(i+1); } wheel_mouse variable indicates if the _current_ event is the wheel but not the modifier.
27-05-2015

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

Will need review for >= JDK 7 Moving to 7u80 and will review ASAP. Ping me directly with any concerns about this move.
22-04-2014