Java JSpinner create from SpinnerNumberModel

Description

Java JSpinner create from SpinnerNumberModel

import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

public class Main extends JFrame {
   public Main() {
      super("java2s.com");

      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setLayout(new FlowLayout());

      int minValue = 1;
      int maxValue = 10;
      int currentValue = 5;
      int steps = 1;
      SpinnerNumberModel nModel = new SpinnerNumberModel(currentValue, minValue, maxValue, steps);
      JSpinner spinner = new JSpinner(nModel);

      getContentPane().add(spinner);/*  w  w  w .  j  a  v a 2 s. co m*/
   }

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



PreviousNext

Related