src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboPopup.java

Print this page

        

@@ -182,10 +182,12 @@
      *
      * @see #createItemListener
      */
     protected ItemListener             itemListener;
 
+    private MouseWheelListener         scrollerMouseWheelListener;
+
     /**
      * This protected field is implementation specific. Do not access directly
      * or override.
      */
     protected Timer                    autoscrollTimer;

@@ -309,10 +311,11 @@
             comboBox.removeItemListener( itemListener );
         }
         uninstallComboBoxModelListeners(comboBox.getModel());
         uninstallKeyboardActions();
         uninstallListListeners();
+        uninstallScrollerListeners();
         // We do this, otherwise the listener the ui installs on
         // the model (the combobox model in this case) will keep a
         // reference to the list, causing the list (and us) to never get gced.
         list.setModel(EmptyListModel);
     }

@@ -606,10 +609,11 @@
      */
     protected void configureScroller() {
         scroller.setFocusable( false );
         scroller.getVerticalScrollBar().setFocusable( false );
         scroller.setBorder( null );
+        installScrollerListeners();
     }
 
     /**
      * Configures the popup portion of the combo box. This method is called
      * when the UI class is created.

@@ -622,10 +626,24 @@
         add( scroller );
         setDoubleBuffered( true );
         setFocusable( false );
     }
 
+    private void installScrollerListeners() {
+        scrollerMouseWheelListener = getHandler();
+        if (scrollerMouseWheelListener != null) {
+            scroller.addMouseWheelListener(scrollerMouseWheelListener);
+        }
+    }
+
+    private void uninstallScrollerListeners() {
+        if (scrollerMouseWheelListener != null) {
+            scroller.removeMouseWheelListener(scrollerMouseWheelListener);
+            scrollerMouseWheelListener = null;
+        }
+    }
+
     /**
      * This method adds the necessary listeners to the JComboBox.
      */
     protected void installComboBoxListeners() {
         if ((propertyChangeListener = createPropertyChangeListener()) != null) {

@@ -833,12 +851,12 @@
         }
     }
 
 
     private class Handler implements ItemListener, MouseListener,
-                          MouseMotionListener, PropertyChangeListener,
-                          Serializable {
+                          MouseMotionListener, MouseWheelListener,
+                          PropertyChangeListener, Serializable {
         //
         // MouseListener
         // NOTE: this is added to both the JList and JComboBox
         //
         public void mouseClicked(MouseEvent e) {

@@ -1022,10 +1040,17 @@
                 @SuppressWarnings("unchecked")
                 JComboBox<Object> comboBox = (JComboBox)e.getSource();
                 setListSelection(comboBox.getSelectedIndex());
             }
         }
+
+        //
+        // MouseWheelListener
+        //
+        public void mouseWheelMoved(MouseWheelEvent e) {
+            e.consume();
+        }
     }
 
     //
     // end Event Listeners
     //=================================================================