Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substance Look and Feel is making my colors brighter?

I'm trying to call setBackground on a JPanel, so that it matches the color of my JFrame, but the color is some how brighter than the one I type in.

I've have tried setting HSB, RGB, HEX code, they all give me the same color, a brighter version of my color.

Don't quite know how to get the color I want?

edit:

I get my colors from Photoshop. I look up the right colors (that i want) and copy the HSB RGB or HEX code. It looks as it should in Photoshop, but java gives me e brighter color?enter image description here

I have used the java code:

Color color = new Color(0x94b3c7); 

    jpanel.setBackground(color);
like image 494
Handsken Avatar asked Oct 04 '11 09:10

Handsken


2 Answers

Substance is 'colorizing' your background colors to try and add some of the theme's color. If you used different skins, you would get different results. The Autumn skin, for example, would make things very orange. This can be changed on a component per component basis by setting the client property org.pushingpixels.substance.api.SubstanceLookAndFeel#COLORIZATION_FACTOR to 1.0. For example:

frame.putClientProperty(SubstanceLookAndFeel.COLORIZATION_FACTOR, 1.0)

This will instruct the background painter to use 100% of the user specified background color, rather than using 50% of the color.

This can also be set globally...

UIManager.put(SubstanceLookAndFeel.COLORIZATION_FACTOR, 1.0);

again, subject to per component overrides. If not set the defaults colorization factor is 0.5.

like image 180
shemnon Avatar answered Nov 05 '22 17:11

shemnon


This SSCCE shows the color in your Photoshop sample:

public class ColorTest {

    public static void main(String[] args) {
        JLabel label = new JLabel("Java Color");
        label.setFont(label.getFont().deriveFont(20f));
        label.setForeground(Color.WHITE);
        label.setBackground(new Color(0x94b3c7));
        label.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        label.setOpaque(true);

        JPanel jpanel = new JPanel();
        jpanel.setOpaque(true);
        jpanel.add(label);
        jpanel.setBackground(Color.GREEN);

        JFrame frame = new JFrame();
        frame.setContentPane(jpanel);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}

Perhaps this helps reveal to you how you should be setting the color to get what you want?

Edit: Now added explicit setting of opaque to try to solve Substance L&F problem.

like image 6
Steve McLeod Avatar answered Nov 05 '22 18:11

Steve McLeod