Pages

Complete source code below will show you, how to set JSlider tick color. I have tried to find method in JSlider class to set JSlider tick color...but, i can't find it. So i tried to create UI Delegate only for SliderUI that change JSlider tick color. You can try to compile both source code below. Make sure both java file below locate at the same location. JSlider's tick color is set in MyNewMetalSliderUI.java.You can try to change it's color follow what color that you want base on RGB value. After you compile SetJSliderTickColor.java and MyNewMetalSliderUI.java, you try execute SetJSliderTickColor.java. This is because, main method contain in this file.Oooo...before i forget, it's only handle horizontal slider. If you want to make it can use for vertical slider, you can try overwrite method paintMajorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) and paintMinorTickForVertSlider(Graphics g, Rectangle tickBounds, int y) in MetalSliderUI class. You can review it in Java SE API for MetalSliderUI class.

if(slider.getOrientation()==JSlider.HORIZONTAL) { //Create color using RGB value(RED=255,GREEN=0,BLUE=0) //You can use Color picker above to get RGB value for color that you want Color majorTickColor=new Color(255,0,0);

//Set color that will use to draw MAJOR TICK using created color g.setColor(majorTickColor);

if(slider.getOrientation()==JSlider.HORIZONTAL) { //Create color using RGB value(RED=12,GREEN=255,BLUE=0) //You can use Color picker above to get RGB value for color that you want Color majorTickColor=new Color(12,255,0);

//Set color that will use to draw MINOR TICK using created color g.setColor(majorTickColor);