JSlider tick

Source code below will show you, how to set major and minor tick for a JSlider and make the tick visible on JSlider.

************************************************************************
COMPLETE SOURCE CODE FOR : JSliderTick.java
************************************************************************


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

import java.awt.FlowLayout;

public class JSliderTick
{
public static void main(String[]args)
{
//Create a slider using JSlider
//Maximum value = 100
//Minimum value = 0
//Initial value = 50
JSlider slider=new JSlider();

//Set minor tick spacing to 1
slider.setMinorTickSpacing(1);

//Set major tick spacing to 10
slider.setMajorTickSpacing(10);

//Enable tick on JSlider
slider.setPaintTicks(true);

//Create a window using JFrame with title ( JSlider tick )
JFrame frame=new JFrame("JSlider tick");

//Set JFrame layout to FlowLayout
frame.setLayout(new FlowLayout());

//Add created slider into JFrame
frame.add(slider);

//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Set JFrame size to :
//WIDTH : 400 pixels
//HEIGHT : 200 pixels
frame.setSize(400,200);

//Make JFrame visible. So, we can see it.
frame.setVisible(true);
}
}


************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************