Example usage for javax.swing JSlider getMajorTickSpacing

List of usage examples for javax.swing JSlider getMajorTickSpacing

Introduction

In this page you can find the example usage for javax.swing JSlider getMajorTickSpacing.

Prototype

public int getMajorTickSpacing() 

Source Link

Document

This method returns the major tick spacing.

Usage

From source file:Main.java

public static void setTickMarkers(JSlider slider) {
    final int min = slider.getMinimum();
    final int max = slider.getMaximum();
    final int delta = max - min;

    if (delta > 0) {
        final int sliderSize;
        if (slider.getOrientation() == SwingConstants.HORIZONTAL)
            sliderSize = slider.getPreferredSize().width;
        else// w w w  .j a v  a  2 s .c  o m
            sliderSize = slider.getPreferredSize().height;

        // adjust ticks space on slider
        final int majTick = findBestMajTickSpace(sliderSize, delta);

        slider.setMinorTickSpacing(Math.max(1, majTick / 5));
        slider.setMajorTickSpacing(majTick);
        slider.setLabelTable(slider.createStandardLabels(slider.getMajorTickSpacing(), majTick));
    }
}