リスナーを付ければ解決だよ!
import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.util.Vector; import javax.swing.ComboBoxModel; import javax.swing.JComboBox; public class JComboBox2 extends JComboBox { public JComboBox2() { super(); setListerner(); } public JComboBox2(ComboBoxModel aModel) { super(aModel); setListerner(); } public JComboBox2(Object[] items) { super(items); setListerner(); } public JComboBox2(Vector<?> items) { super(items); setListerner(); } private void setListerner() { class Listener implements MouseWheelListener { public void mouseWheelMoved(MouseWheelEvent mousewheelevent) { int n = mousewheelevent.getWheelRotation() > 0 ? 1 : -1; int i = getSelectedIndex(); if(i != -1) { int x = i + n; if((0 <= x) && (x < getItemCount())) { setSelectedIndex(x); } } } } this.addMouseWheelListener(new Listener()); } }
コメント