JColorChooser
has a getColor
method which returns a Color
which has methods getRed
, getGreen
and getBlue
respectively
How to get a RGB value from Color variable
Pregunta
JColorChooser.showDialog(tEkran, "Select a Color", selectedColorBG);
After a choice a colour I need to transfer it to 3 variable. Like this:
colorR = selectedColorBG.getR
colorG = selectedColorBG.getG
colorB = selectedColorBG.getB
Is there any way to do that ?
Solución
Otros consejos
You must process the return value:
Color selectedColor = JColorChooser.showDialog(tEkran, "Select the color", initialColor);
int red = selectedColor.getRed();
int green = selectedColor.getGreen();
int blue = selectedColor.getBlue();
A look at the java.awt.Color
documentation would have answered your question:
int getAlpha()
Returns the alpha component in the range 0-255.
int getBlue()
Returns the blue component in the range 0-255 in the default sRGB space.
int getGreen()
Returns the green component in the range 0-255 in the default sRGB space.
int getRed()
Returns the red component in the range 0-255 in the default sRGB space.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow