문제

I there a way to get the color that is behind the slider portion of a JSlider? For Example, I made a program (see Image Below) that creates a gradient and requires the user to pick a color with a JSlider. Is there a way to get the color that the JSlider stops at?

enter image description here

도움이 되었습니까?

해결책

If you can get a point on the slider you could use.

Color color = robot.getPixelColor((int)coord.getX(), (int)coord.getX())

The pseudo code would look like

 Robot robot = new Robot();
 int xValue = slider.getLocationOnScreen().x + (int)(slider.getValue()/(double)(slider.getMaximum()-slider.getMinimum()) * slider.getWidth() +.5);//Calculates distance of the sliders' position).
 int yValue = slider.getLocationOnScreen().y + slider.getHeight()/2;//Calculates a y-value to extract the pixel from. 
 Color color = robot.getPixelColor(xValue,yValue);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top