Search code examples
javaswinguser-interfacejslider

How to unfill JSlider left portion?


When I slide the JSlider to the right, the left portion becomes filled with a color. Is it possible to not have it filled, and if so, how would I do so?

This is my code right now:

public void drawSlider() {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 1, 10, 5);
    slider.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    slider.setPaintLabels(true);
    slider.setMajorTickSpacing(1);
    slider.setPaintTicks(true);
    slider.setBounds(56, 293, 224, 65);
    this.getContentPane().add(slider);
}

Solution

  • You could do

    slider.putClientProperty("JSlider.isFilled", Boolean.FALSE);