Java Swing How to - Create Spinner model from String array








Question

We would like to know how to create Spinner model from String array.

Answer

/* www.  j ava2 s .  c  o  m*/
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;

public class Main {
  public static void main(String[] argv) throws Exception {
    SpinnerListModel listModel = new SpinnerListModel(new String[] { "red","green", "blue" });
    JSpinner spinner = new JSpinner(listModel);

    spinner.setValue("blue");
  }
}