Swing/CyclingSpinnerModel のバックアップソース(No.4)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- バックアップ を表示
- Swing/CyclingSpinnerModel へ行く。
- 1 (2010-02-01 (月) 01:53:39)
- 2 (2012-08-11 (土) 21:01:12)
- 3 (2013-01-02 (水) 14:32:49)
- 4 (2015-01-01 (木) 21:39:39)
- 5 (2016-05-06 (金) 15:48:18)
- 6 (2017-04-04 (火) 14:17:08)
- 7 (2017-08-03 (木) 15:43:40)
- 8 (2018-08-07 (火) 14:34:46)
- 9 (2020-08-06 (木) 12:17:42)
- 10 (2021-12-23 (木) 17:19:08)
- 11 (2023-09-19 (火) 16:04:07)
--- title: JSpinnerのモデルの値をループさせる tags: [JSpinner, SpinnerNumberModel] author: aterai pubdate: 2010-02-01T01:53:39+09:00 description: JSpinnerのモデルで値が最大、最小を超えるとループするように設定します。 --- * 概要 [#g1e8aa14] `JSpinner`のモデルで値が最大、最小を超えるとループするように設定します。 #download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTKYcCKxAI/AAAAAAAAAV4/T8OdovAF6EY/s800/CyclingSpinnerModel.png) * サンプルコード [#ld341dbc] #code(link){{ spinner.setModel(new SpinnerNumberModel(20, 0, 59, 1) { @Override public Object getNextValue() { Object n = super.getNextValue(); if(n==null) n = getMinimum(); return n; } @Override public Object getPreviousValue() { Object n = super.getPreviousValue(); if(n==null) n = getMaximum(); return n; } }); }} * 解説 [#m44dfbfa] 上記のサンプルでは、各モデルの`getNextValue`、`getPreviousValue`メソッドをオーバーライドすることでループするように設定しています。 * 参考リンク [#w63c8b19] - [http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html#model Creating Custom Spinner Models and Editors] * コメント [#d1f3740f] #comment #comment