Change colors for JProgressBar with Nimbus?

后端 未结 3 561
一整个雨季
一整个雨季 2020-12-06 07:29

does anyone know how to change the colors for JProgressBar when you use Nimbus LookAndFeel?

3条回答
  •  生来不讨喜
    2020-12-06 08:16

    I have overridden the whole nimbusOrange-Default Value, which change all ProgressBar-Colors and any other nimbusOrange. (InternalFrame - minimize Button)
    here with nimbusBase (blue)

    UIDefaults defaults = UIManager.getLookAndFeelDefaults();
    defaults.put("nimbusOrange",defaults.get("nimbusBase"));
    

    Better is to write a own Painter and set this to the UIManager via

    UIManager.put("ProgressBar[Enabled].backgroundPainter", myPainter);
    

    If You want to change the Color for only a single ProgressBar instance, you can use Per-component customization

    progress = new JProgressBar();
    UIDefaults defaults = new UIDefaults();
    defaults.put("ProgressBar[Enabled].backgroundPainter", new MyPainter());
    progress.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    progress.putClientProperty("Nimbus.Overrides", defaults);
    

提交回复
热议问题