0

I want to change default value of object according to LookAndFeel.

For LookAndFeel on Java some has the same objects, but different value. Example:

Metal : javax.swing.plaf.metal.MetalLookAndFeel
    Slider.background : javax.swing.plaf.ColorUIResource[r=238,g=238,b=238]
    SliderUI : javax.swing.plaf.metal.MetalSliderUI

Nimbus : javax.swing.plaf.nimbus.NimbusLookAndFeel
    Slider.background : DerivedColor(color=214,217,223 parent=control offsets=0.0,0.0,0.0,0 pColor=214,217,223
    SliderUI : javax.swing.plaf.synth.SynthLookAndFeel


CDE/Motif : com.sun.java.swing.plaf.motif.MotifLookAndFeel
    Slider.background : javax.swing.plaf.ColorUIResource[r=147,g=151,b=165]
    SliderUI : com.sun.java.swing.plaf.motif.MotifSliderUI


GTK+ : com.sun.java.swing.plaf.gtk.GTKLookAndFeel
    Slider.background : javax.swing.plaf.ColorUIResource[r=214,g=210,b=208]
    SliderUI : javax.swing.plaf.synth.SynthLookAndFeel


Mac OS X : com.apple.laf.AquaLookAndFeel
    Slider.background : com.apple.laf.AquaImageFactory$SystemColorProxy[r=238,g=238,b=238]
    SliderUI : com.apple.laf.AquaSliderUI


Windows : com.sun.java.swing.plaf.windows.WindowsLookAndFeel
    Slider.background : javax.swing.plaf.ColorUIResource[r=240,g=240,b=240]
    SliderUI : com.sun.java.swing.plaf.windows.WindowsSliderUI


Windows Classic : com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel
    Slider.background : javax.swing.plaf.ColorUIResource[r=240,g=240,b=240]
    SliderUI : com.sun.java.swing.plaf.windows.WindowsSliderUI

.

You can see that has the same object, in this case Slider.background but has different default values, according to LookAndFeel.

I want to know: how change default value (establishing another values different between them) for Nimbus, for Metal and Motif.

Example:

Metal -> Slider.background:Color.RED
Nimbus -> Slider.background:Color.GREEN
Motif -> Slider.background:Color.BLUE

The problem of next method is changes for all, but How select the specific LAF?

UIDefaults sliderDefaults = new UIDefaults();
sliderDefaults.put("Slider.background", THE_COLOR_SELECTED);
UIManager.put("Slider.background", THE_COLOR_SELECTED);

I don't want to set the LookAndFeel to change its value's component... I want to change before the LookAndFeel, and apply it later changed LAF (I don't know if is possible).

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");

Suppose exist a method (this really doesn't work) like this:

UIManager.getLookAndFeel("javax.swing.plaf.metal.MetalLookAn‌​dFeel").put("Slider.‌​background", Color.RED); 
UIManager.getLookAndFeel("com.sun.java.swing.plaf.motif.Moti‌​fLookAndFeel").put("‌​Slider.background", Color.GREEN); 
UIManager.getLookAndFeel("javax.swing.plaf.nimbus.NimbusLook‌​AndFeel").put("Slide‌​r.background", Color.BLUE);

According to LookAndFeel, I'm establishing a different DEFAULT Color for the same object.

Note: The Color is only for demonstration porpoise, because I want to use the same principle to other types of objects.

QA_Col
  • 1,095
  • 9
  • 23
  • The Problem its changes all LAF, I use to changes font for all LookAndFeel. How set a specific value according to LAF? – QA_Col Jun 03 '17 at 00:26
  • Maybe a custom `ComponentUI`, like this [`SliderUI`](https://stackoverflow.com/a/6996263/230513). – trashgod Jun 03 '17 at 00:35
  • Please, don delete the comment I will take account... Now If you note `Nimbus` and `GTK` uses the same SliderUI `javax.swing.plaf.synth.SynthLookAndFeel`, How changes for One but not for another? – QA_Col Jun 03 '17 at 00:39
  • I really don't understand what you want. Maybe something like [this](https://stackoverflow.com/a/14262706/230513). – trashgod Jun 03 '17 at 07:21
  • Code in comments to hard to read, and it sheds no light on what you want to do. Please edit your question to include the new code as well as a [mcve] that exhibits the problem you want to solve. See also the custom implementation of `updateUI()` in this [example](https://stackoverflow.com/a/7137801/230513). – trashgod Jun 04 '17 at 03:29

0 Answers0