Swing/ColorComboBox のバックアップの現在との差分(No.1)
2021-11-17 (水) 04:12:37
- category: swing folder: ColorComboBox title: JComboBoxの色を変更 tags: [JComboBox, ListCellRenderer, JTextField] author: aterai pubdate: 2005-01-10T01:48:08+09:00 description: JComboBoxのEditor部分と、List部分の色を変更します。 image: hreflang:
href: https://java-swing-tips.blogspot.com/2009/06/color-jcombobox.html lang: en
概要
JComboBox
のEditor
部分と、List
部分の色を変更します。
Screenshot
Advertisement
サンプルコード
解説
上記のサンプルでは、JComboBox
を編集可にした状態で以下のようにList
部分、Editor
部分に行の奇数偶数で背景色を変更しています。
-
List
部分-
ListCellRenderer
を使用することで背景色を変更
-
-
Editor
部分-
getEditor().getEditorComponent()
でJTextField
オブジェクトを取得して背景色を変更
-
- -
-
GTKLookAndFeel
などでBox
(Editor
)部分の色を変更できない場合がある