Java SpinnerListModel create from String array

Description

Java SpinnerListModel create from String array

import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;

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

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


      SpinnerListModel listModel = new SpinnerListModel(new String[] { "red","green", "blue" });
      JSpinner spinner = new JSpinner(listModel);

      /* ww w .j  ava  2  s  .c  o m*/
      getContentPane().add(spinner);
   }

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



PreviousNext

Related