14

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);
Handsken
  • 664
  • 11
  • 26
  • 11
    Java makes you brighter :) – dacwe Oct 04 '11 at 09:37
  • 7
    You need to provide an [SSCCE](http://sscce.org). – aioobe Oct 04 '11 at 09:40
  • 1
    You get an upvote for the title, but you *need* to provide an example (as aioobe noted) *and* need to tell us where you got the value from, *which* color you try to set and *why* you think it should look different from what it does. Does it have an alpha value? – Joachim Sauer Oct 04 '11 at 09:45
  • Thank you i will look in to SSCCE – Handsken Oct 04 '11 at 09:46
  • Interesting: when I check these colors in Gimp the Java Color is `cde0ee`, the Photoshop Color is `94b3c7` and `1d557a` (as in the source code) is even darker (but a similar hue). – Joachim Sauer Oct 04 '11 at 10:00
  • Try to paste this color code somwhere else. In html page, css (look at it in browser), into some other Gimp or Paint.NET or even into Kuler and compare. You Photoshop may have some strange color space set or something like this. Pick the color from your rendered JFrame with some screen color picker and check the HEX color. – Piotr Gwiazda Oct 04 '11 at 10:03
  • Thanks will check it out, On Joachim's answer: It's my bad I edited the wrong HEX code in my question, I use the `94b3c7` for java, its the HEX i get from photoshop. Could it have anything to do with my Panel? shouldn't int be on top? Its a panel that's added to a contentPane. – Handsken Oct 04 '11 at 10:42
  • 3
    could it be that your photoshop is set to a different color proof than your monitor? – clamp Oct 04 '11 at 11:47
  • Are You running Windows by any chance? – Maurice Perry Oct 04 '11 at 11:51
  • Yes im running Windows, that has hardly anything to do with the solution. – Handsken Oct 04 '11 at 12:07

3 Answers3

11

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.

shemnon
  • 5,318
  • 4
  • 28
  • 37
6

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.

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
  • 1
    Great! I've tried your code, and i got the correct color. It took a bit scouting in my code but i think i found the problem. Im using a skin for my JFrame: `import org.pushingpixels.substance.api.skin.SubstanceBusinessBlueSteelLookAndFeel;` – Handsken Oct 04 '11 at 11:57
  • And when i don't use the better looking JFrame it works, but then I don't need it to work. In not happy with the truth :( – Handsken Oct 04 '11 at 12:05
  • 1
    This could be an "opaque" problem. I've modified my sample code to include setting opaque to true on both the JPanel and the JLabel. The panel should now be green, with the label the desired color (0x94b3c7) – Steve McLeod Oct 04 '11 at 13:07
3

So I've found the problem. It's actually kind of annoying, and I probably should have added this in the question, but I never thought that this was causing the problem.

Se im using something called Substance.api from the webpage http://www.pushing-pixels.org

Its a colorskin for the GUI, My intention was to change the color of the JFrame, but insted I changed the whole color proof.

So if someone knows how to change the JFrame Color, hawla at me! :)

This is the bandit code:

public static void main(String[] args) {

    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                UIManager.setLookAndFeel(new SubstanceRavenLookAndFeel());
            } catch (Exception e) {
            }
        }
    });
}
Miss Chanandler Bong
  • 4,081
  • 10
  • 26
  • 36
Handsken
  • 664
  • 11
  • 26