Swing/ClearComboBoxItemSelection のバックアップ差分(No.5)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/ClearComboBoxItemSelection へ行く。
- 1 (2017-03-27 (月) 13:55:22)
- 2 (2017-10-05 (木) 14:38:22)
- 3 (2017-12-26 (火) 17:06:03)
- 4 (2018-02-15 (木) 14:23:42)
- 5 (2019-12-20 (金) 14:54:36)
- 6 (2021-05-31 (月) 15:31:38)
- 7 (2022-08-20 (土) 22:15:25)
- 8 (2024-05-20 (月) 12:09:17)
- 9 (2025-01-03 (金) 08:57:02)
- 10 (2025-01-03 (金) 09:01:23)
- 11 (2025-01-03 (金) 09:02:38)
- 12 (2025-01-03 (金) 09:03:21)
- 13 (2025-01-03 (金) 09:04:02)
- 14 (2025-06-19 (木) 12:41:37)
- 15 (2025-06-19 (木) 12:43:47)
- 追加された行はこの色です。
- 削除された行はこの色です。
--- category: swing folder: ClearComboBoxItemSelection title: JComboBoxを選択なしの状態にする tags: [JComboBox] author: aterai pubdate: 2017-03-27T13:52:28+09:00 description: JComboBoxの項目が何も選択されていない状態になるよう設定します。 image: https://drive.google.com/uc?export=view&id=1ytLrgrvvfQGy-YNgOPiY67cT8EaLV1yHoA image: https://drive.google.com/uc?id=1ytLrgrvvfQGy-YNgOPiY67cT8EaLV1yHoA --- * 概要 [#summary] `JComboBox`の項目が何も選択されていない状態になるよう設定します。 #download(https://drive.google.com/uc?export=view&id=1ytLrgrvvfQGy-YNgOPiY67cT8EaLV1yHoA) #download(https://drive.google.com/uc?id=1ytLrgrvvfQGy-YNgOPiY67cT8EaLV1yHoA) * サンプルコード [#sourcecode] #code(link){{ combo.setSelectedIndex(-1); //or: combo.setSelectedItem(null); }} * 解説 [#explanation] 上記のサンプルでは、`JComboBox#setSelectedIndex(-1)`や`JComboBox#setSelectedItem(null)`で、`JComboBox`の項目がどれも選択されていない状態にするテストを行っています。 - メモ -- [https://bugs.openjdk.java.net/browse/JDK-4180057 JDK-4180057 JComboBox needs to document that setSelectedIndex( -1 ) means no selection - Java Bug System] --- `JComboBox#setSelectedIndex(-1)`で選択状態がクリアされるのは当初からの仕様だが、ドキュメントに記述されたのは`1.4.0`からになる(日本語版は`1.7.0`から) -- `JComboBox`のアイテム選択の初期状態: --- 項目数`== 0`の場合は、`-1` --- 項目数`> 0`の場合は、`0` -- `-1`以外の負の値は範囲外となり、例外が発生する: --- `java.lang.IllegalArgumentException: setSelectedIndex: -2 out of bounds` * 参考リンク [#reference] - [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/JComboBox.html#setSelectedIndex-int- JComboBox#setSelectedIndex(int) (Java Platform SE 8)] - [https://bugs.openjdk.java.net/browse/JDK-4180057 JDK-4180057 JComboBox needs to document that setSelectedIndex( -1 ) means no selection - Java Bug System] * コメント [#comment] #comment #comment