Swing/WheelCombo のバックアップソース(No.12)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/WheelCombo へ行く。
- 1 (2004-11-15 (月) 02:34:50)
- 2 (2005-04-28 (木) 04:33:11)
- 3 (2005-06-08 (水) 02:19:53)
- 4 (2005-07-01 (金) 17:04:53)
- 5 (2005-09-21 (水) 21:53:37)
- 6 (2006-02-27 (月) 16:39:06)
- 7 (2007-03-10 (土) 01:38:00)
- 8 (2007-10-06 (土) 21:29:51)
- 9 (2012-06-21 (木) 20:34:37)
- 10 (2013-04-14 (日) 00:27:22)
- 11 (2015-01-30 (金) 19:38:48)
- 12 (2016-08-03 (水) 17:05:05)
- 13 (2017-09-18 (月) 18:48:11)
- 14 (2019-02-22 (金) 20:33:46)
- 15 (2020-12-08 (火) 10:55:09)
- 16 (2021-11-16 (火) 08:22:44)
- 17 (2025-01-03 (金) 08:57:02)
- 18 (2025-01-03 (金) 09:01:23)
- 19 (2025-01-03 (金) 09:02:38)
- 20 (2025-01-03 (金) 09:03:21)
- 21 (2025-01-03 (金) 09:04:02)
- 22 (2025-06-19 (木) 12:41:37)
- 23 (2025-06-19 (木) 12:43:47)
--- title: JComboBoxの値をMouseWheelで変更 tags: [JComboBox, MouseWheelListener] author: aterai pubdate: 2004-11-15T02:34:50+09:00 description: JComboBoxにフォーカスがある場合、その値をMouseWheelの上下で変更します。 --- * 概要 [#summary] `JComboBox`にフォーカスがある場合、その値を`MouseWheel`の上下で変更します。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTWm95sa5I/AAAAAAAAApg/1tiQsmg5QKw/s800/WheelCombo.png) * サンプルコード [#sourcecode] #code(link){{ JComboBox<String> combo = makeComboBox(); combo.addMouseWheelListener(new MouseWheelListener() { @Override public void mouseWheelMoved(MouseWheelEvent e) { JComboBox source = (JComboBox) e.getComponent(); if (!source.hasFocus()) { return; } int ni = source.getSelectedIndex() + e.getWheelRotation(); if (ni >= 0 && ni < source.getItemCount()) { source.setSelectedIndex(ni); } } }); }} * 解説 [#explanation] 上記のサンプルでは、一番上のコンボボックスに`MouseWheelListener`が設定され、マウスホイールの上下回転に反応して、表示される内容が順次変更されるようになっています。 //* 参考リンク [#reference] * コメント [#comment] #comment #comment