src/java.desktop/share/classes/javax/swing/plaf/basic/BasicComboBoxUI.java
Print this page
@@ -148,10 +148,12 @@
/**
* The {@code KeyListener} listens to events.
*/
protected KeyListener popupKeyListener;
+ private MouseWheelListener mouseWheelListener;
+
// This is used for knowing when to cache the minimum preferred size.
// If the data in the list changes, the cached value get marked for recalc.
// Added to the current JComboBox model
/**
* This protected field is implementation specific. Do not access directly
@@ -411,10 +413,14 @@
if ( comboBox.getModel() != null ) {
if ( (listDataListener = createListDataListener()) != null ) {
comboBox.getModel().addListDataListener( listDataListener );
}
}
+
+ if ((mouseWheelListener = createMouseWheelListener()) != null) {
+ comboBox.addMouseWheelListener(mouseWheelListener);
+ }
}
/**
* Uninstalls the default colors, default font, default renderer,
* and default editor from the combo box.
@@ -457,10 +463,13 @@
if ( comboBox.getModel() != null ) {
if ( listDataListener != null ) {
comboBox.getModel().removeListDataListener( listDataListener );
}
}
+ if (mouseWheelListener != null) {
+ comboBox.removeMouseWheelListener(mouseWheelListener);
+ }
}
/**
* Creates the popup portion of the combo box.
*
@@ -570,10 +579,14 @@
handler = new Handler();
}
return handler;
}
+ private MouseWheelListener createMouseWheelListener() {
+ return getHandler();
+ }
+
//
// end UI Initialization
//======================
@@ -1721,11 +1734,12 @@
//
// Shared Handler, implements all listeners
//
private class Handler implements ActionListener, FocusListener,
KeyListener, LayoutManager,
- ListDataListener, PropertyChangeListener {
+ ListDataListener, PropertyChangeListener,
+ MouseWheelListener {
//
// PropertyChangeListener
//
public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
@@ -1995,11 +2009,11 @@
// from the editor may be handled by the JComboBox in which case, the
// enterPressed action will always be invoked.
public void actionPerformed(ActionEvent evt) {
Object item = comboBox.getEditor().getItem();
if (item != null) {
- if(!comboBox.isPopupVisible() && !item.equals(comboBox.getSelectedItem())) {
+ if (!comboBox.isPopupVisible() && !item.equals(comboBox.getSelectedItem())) {
comboBox.setSelectedItem(comboBox.getEditor().getItem());
}
ActionMap am = comboBox.getActionMap();
if (am != null) {
Action action = am.get("enterPressed");
@@ -2009,10 +2023,14 @@
evt.getModifiers()));
}
}
}
}
+
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ e.consume();
+ }
}
class DefaultKeySelectionManager implements JComboBox.KeySelectionManager, UIResource {
private String prefix = "";
private String typedString = "";