Frage

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 ?

War es hilfreich?

Lösung

JColorChooser has a getColor method which returns a Color which has methods getRed, getGreen and getBlue respectively

Andere Tipps

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.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top