문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

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.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top