JSlider label

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

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


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

import java.awt.FlowLayout;

public class JSliderLabel
{
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 label on JSlider
slider.setPaintLabels(true);

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

//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
**************************************************************************

RELAXING NATURE VIDEO