TickSliders.java Source code

Java tutorial

Introduction

Here is the source code for TickSliders.java

Source

/*
Definitive Guide to Swing for Java 2, Second Edition
By John Zukowski       
ISBN: 1-893115-78-X
Publisher: APress
*/

import java.awt.BorderLayout;
import java.awt.Container;

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

public class TickSliders {
    public static void main(String args[]) {
        JFrame f = new JFrame("Tick Slider");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        // No Ticks
        JSlider jSliderOne = new JSlider();
        // Major Tick 25 - Minor 5
        JSlider jSliderTwo = new JSlider();
        jSliderTwo.setMinorTickSpacing(5);
        jSliderTwo.setMajorTickSpacing(25);
        jSliderTwo.setPaintTicks(true);
        jSliderTwo.setSnapToTicks(true);
        // Major Tick 25 - Minor 6
        JSlider jSliderThree = new JSlider(JSlider.VERTICAL);
        jSliderThree.setMinorTickSpacing(6);
        jSliderThree.setMajorTickSpacing(25);
        jSliderThree.setPaintTicks(true);
        JSlider jSliderFour = new JSlider(JSlider.VERTICAL);
        // Major Tick 25 - Minor 1
        jSliderFour.setMinorTickSpacing(1);
        jSliderFour.setMajorTickSpacing(25);
        jSliderFour.setPaintTicks(true);

        Container c = f.getContentPane();
        c.add(jSliderOne, BorderLayout.NORTH);
        c.add(jSliderTwo, BorderLayout.SOUTH);
        c.add(jSliderThree, BorderLayout.WEST);
        c.add(jSliderFour, BorderLayout.EAST);
        f.setSize(300, 200);
        f.setVisible(true);
    }
}