I have a program with some gui, on the JFrame I set,
setBackground( new Color(107, 106, 104) );
The issue is that I get a greyish color, but not the right one. If I check it in PhotoShop, it gives me the RGB values (126, 125, 123)
Ps. I have tried with HEX value, the same result.
To create your own color: Paint - Double click on any color at the bottom of the screen. - Choose "Define Custom Colors". - Select a color and/or use the arrows to achieve the desired color. are the numbers needed to create your new Java color.
Definition and Usage. The rgb() function define colors using the Red-green-blue (RGB) model. An RGB color value is specified with: rgb(red, green, blue). Each parameter defines the intensity of that color and can be an integer between 0 and 255 or a percentage value (from 0% to 100%).
Since 255 is the maximum value, dividing by 255 expresses a 0-1 representation. Each channel (Red, Green, and Blue are each channels) is 8 bits, so they are each limited to 256, in this case 255 since 0 is included.
I have a program with some gui, on the JFrame I set,
setBackground( new Color(107, 106, 104) );
[The problem] It gives a greyish color, but not the right one!
If I check the gui's color in Photo Shop, it gives me the RGB
values (126, 125, 123)
you can not set setBackground for JFrame, this is only possible for ContentPane, for example
JFrame#getContentPane.setBackground(new Color(107, 106, 104));
EDIT

from code
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class Check extends JFrame {
private static final long serialVersionUID = 1L;
public void makeUI() {
JFrame f = new JFrame();
f.getContentPane().setBackground(new Color(107, 106, 104));
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
f.setSize(new Dimension(300, 200));
f.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Check().makeUI();
}
});
}
}
check with Adam's comment and even if not worked then without any working code I am just guessing that this scenario is getting raised due zero ordering or saying layout of the JFrame. Actually in java swing , setting the background color needs a little bit of more attention, check Swing Java Docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With