#navi(../)
*JComboBoxの値をMouseWheelで変更 [#i7ef2fc7]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2004-11-15~
更新日:&lastmod;

#contents
**概要 [#fb21376c]
JComboBoxにフォーカスがある場合、その値をMouseWheelの上下で変更します。

http://terai.xrea.jp/swing/wheelcombo/screenshot.png

**サンプルコード [#ef581a0a]
 combo.addMouseWheelListener(new MouseWheelListener() {
   public void mouseWheelMoved(MouseWheelEvent e) {
     JComboBox source = (JComboBox) e.getSource();
     if(!source.hasFocus()) return;
     int ni = source.getSelectedIndex() + e.getWheelRotation();
     if(ni>=0 && ni<source.getItemCount()) {
       source.setSelectedIndex(ni);
     }
   }
 });

-[[サンプルを起動>http://terai.xrea.jp/swing/wheelcombo/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/wheelcombo/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/wheelcombo/src.zip]]

**解説 [#r2f99b4c]
上記のサンプルでは、一番上のコンボボックスにMouseWheelListenerを設定しています。マウスホイールの上下回転に反応して、表示される内容が順次移動するようになっています。

//**参考リンク
**コメント [#ebca23c2]
#comment