JCheckBoxとJRadioButtonのチェックアイコン背景色を変更する
Total: 735, Today: 1, Yesterday: 1
Posted by aterai at
Last-modified:
Summary
JCheckBoxとJRadioButtonのチェックアイコン内部の描画に使用するインテリア背景色などを変更します。
Screenshot

Advertisement
Source Code Examples
try {
UIManager.setLookAndFeel(
"com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
} catch (Exception ignored) {
Toolkit.getDefaultToolkit().beep();
}
// System.setProperty("swing.noxp", "true");
UIManager.put("CheckBox.foreground", Color.RED);
UIManager.put("CheckBox.background", Color.GREEN);
UIManager.put("CheckBox.interiorBackground", Color.BLUE);
UIManager.put("RadioButton.foreground", Color.RED);
UIManager.put("RadioButton.background", Color.GREEN);
UIManager.put("RadioButton.interiorBackground", Color.BLUE);
View in GitHub: Java, KotlinDescription
CheckBox.interiorBackground、RadioButton.interiorBackground:BLUEJCheckBoxとJRadioButtonのチェックアイコン内部のButtonModel#isPressed()でない、かつButtonModel#isArmed()でない状態の背景色WindowsClassicLookAndFeelでのみ有効CheckBoxMenuItem.interiorBackground、RadioButtonMenuItem.interiorBackgroundは存在せず無効
CheckBox.background、RadioButton.background:GREENJCheckBoxとJRadioButtonのラベル背景色- このサンプルでは
JCheckBox#setOpaque(false)を設定してラベルの背景を描画しないよう設定している
- このサンプルでは
WindowsClassicLookAndFeelの場合、ButtonModel#isPressed()、かつButtonModel#isArmed()状態のチェックアイコン内部の背景色も共有している
CheckBox.foreground、RadioButton.foreground:REDJCheckBoxとJRadioButtonのラベル文字色WindowsClassicLookAndFeelの場合、チェックアイコンのチェックマーク色も共有しているMotifLookAndFeelの場合、JCheckBoxのチェックマーク色のみ変更可能で、JRadioButtonのチェックマーク色は変更不可