Example usage for javax.swing JSlider setMajorTickSpacing

List of usage examples for javax.swing JSlider setMajorTickSpacing

Introduction

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

Prototype

@BeanProperty(visualUpdate = true, description = "Sets the number of values between major tick marks.")
public void setMajorTickSpacing(int n) 

Source Link

Document

This method sets 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//from ww w  .j  a va 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));
    }
}

From source file:MainClass.java

public MainClass() {
    super(true);/*  ww w. java 2s. c  o m*/

    JSlider mySlider = new JSlider();
    mySlider.setMajorTickSpacing(20);
    mySlider.setMinorTickSpacing(10);
    mySlider.setPaintTicks(true);
    mySlider.setPaintLabels(true);

    CurvedBorder border = new CurvedBorder(10, Color.darkGray);
    mySlider.setBorder(border);

    add(mySlider);
}

From source file:CurvedExample.java

public CurvedExample() {
    super(true);//from w ww .  j  a  v a  2 s .  c o  m

    JSlider mySlider = new JSlider();
    mySlider.setMajorTickSpacing(20);
    mySlider.setMinorTickSpacing(10);
    mySlider.setPaintTicks(true);
    mySlider.setPaintLabels(true);

    CurvedBorder border = new CurvedBorder(10, Color.darkGray);
    mySlider.setBorder(border);

    add(mySlider);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);//from   www  .  ja v  a 2  s.  c  o  m
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);//from   w  w w. jav a  2s .  co  m
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(true);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    setLayout(new BorderLayout());
    JSlider slider = new JSlider(JSlider.HORIZONTAL, 0, 50, 25);

    slider.setMinorTickSpacing(2);/*from   w  w w  .  j a va2 s  . c  o  m*/
    slider.setMajorTickSpacing(10);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);

    slider.setOrientation(JSlider.VERTICAL);
    slider.setInverted(false);

    // We'll just use the standard numeric labels for now...
    slider.setLabelTable(slider.createStandardLabels(10));

    add(slider, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    Container content = getContentPane();
    content.setBackground(Color.white);

    JSlider slider1 = new JSlider();
    slider1.setBorder(BorderFactory.createTitledBorder("JSlider without Tick Marks"));

    content.add(slider1, BorderLayout.NORTH);

    JSlider slider2 = new JSlider();
    slider2.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks"));

    slider2.setMajorTickSpacing(20);
    slider2.setMinorTickSpacing(5);/*from w w  w .j  av  a 2 s.  c om*/
    slider2.setPaintTicks(true);
    content.add(slider2, BorderLayout.CENTER);

    JSlider slider3 = new JSlider();
    slider3.setBorder(BorderFactory.createTitledBorder("JSlider with Tick Marks & Labels"));

    slider3.setMajorTickSpacing(20);
    slider3.setMinorTickSpacing(5);
    slider3.setPaintTicks(true);
    slider3.setPaintLabels(true);
    content.add(slider3, BorderLayout.SOUTH);

    setSize(300, 300);
    setVisible(true);
}

From source file:Main.java

public JSlider getSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init);
    slider.setPaintTicks(true);/*from ww  w  .ja  v a  2 s .c  o  m*/
    slider.setMajorTickSpacing(mjrTkSp);
    slider.setMinorTickSpacing(mnrTkSp);
    slider.setPaintLabels(true);
    slider.addChangeListener(new SliderListener());
    return slider;
}

From source file:SliderControlPaintLine.java

public JSlider createSlider(JPanel panel, int orientation, int minimumValue, int maximumValue, int initValue,
        int majorTickSpacing, int minorTickSpacing) {
    JSlider slider = new JSlider(orientation, minimumValue, maximumValue, initValue);
    slider.setPaintTicks(true);//w  w w. j  ava  2 s  .c  o  m
    slider.setMajorTickSpacing(majorTickSpacing);
    slider.setMinorTickSpacing(minorTickSpacing);
    slider.setPaintLabels(true);
    slider.addChangeListener(new SliderListener());
    panel.add(slider);
    return slider;
}

From source file:ArcApp.java

public JSlider setSlider(int min, int max, int init, int mjrTkSp, int mnrTkSp) {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, init);
    slider.setPaintTicks(true);/*ww  w .  j a  v a2s  .  com*/
    slider.setMajorTickSpacing(mjrTkSp);
    slider.setMinorTickSpacing(mnrTkSp);
    slider.setPaintLabels(true);
    slider.addChangeListener(new SliderListener());
    return slider;
}