Java Swing How to - Set JSlider Client Properties JSlider.isFilled








Question

We would like to know how to set JSlider Client Properties JSlider.isFilled.

Answer

//from   w ww. j a  va  2s .com
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JSlider;

public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("Tick Slider");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider oneJSlider = new JSlider();
    oneJSlider.putClientProperty("JSlider.isFilled", Boolean.TRUE);
    JSlider anotherJSlider = new JSlider();
    // Set to default setting
    anotherJSlider.putClientProperty("JSlider.isFilled", Boolean.FALSE);
    anotherJSlider.setPaintTicks(true);
 
    frame.add(oneJSlider, BorderLayout.NORTH);
    frame.add(anotherJSlider, BorderLayout.SOUTH);
    frame.setSize(300, 200);
    frame.setVisible(true);
  }
}