Create and use HORIZONTAL Sliders - Java Swing

Java examples for Swing:JSlider

Description

Create and use HORIZONTAL Sliders

Demo Code

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

public class Main extends JFrame {

  public Main() {
    super("Slider");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JSlider pickNum = new JSlider(JSlider.HORIZONTAL, 0, 30, 5);
    pickNum.setMajorTickSpacing(10);//  www  .  j  ava 2  s .  c o  m
    pickNum.setMinorTickSpacing(1);
    pickNum.setPaintTicks(true);
    pickNum.setPaintLabels(true);
    add(pickNum);
    pack();
    setVisible(true);
  }

  public static void main(String[] args) {
    Main frame = new Main();
  }
}

Related Tutorials