Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8041470

JButtons stay pressed after they have lost focus if you use the mouse wheel

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b70
    • CPU:
      x86
    • OS:
      linux

      Backports

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

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                anashaty Anton Nashatyrev (Inactive)
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: