JSpinner with SpinnerListModel

SpinnerListModel is a model for a sequence defined by an array of objects of any type. You could use this to use a sequence of strings as the choices in the spinner.

Program

DSFSDFSDF

 

 

 

Program Source

import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;
import java.awt.FlowLayout;
import java.awt.Dimension;

class JSpinnerTest extends JFrame {
  
    JSpinnerTest()
    {
        setLayout(new FlowLayout());
        setTitle("JSpinnerTest");
        setJSpinner();
        setSize(700,200);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
  
    void setJSpinner()
    {
        String[] data ={"January","February","March","April",
                            "May","June","July","August","September",
                            "October","November","December"};
        SpinnerListModel mod = new SpinnerListModel(data);
        JSpinner js = new JSpinner(mod);
        js.setPreferredSize(new Dimension(100,20));
        add(js);
    }
}

public class Javaapp {
  
    public static void main(String[] args) {
      
        JSpinnerTest js = new JSpinnerTest();
    }
}

Leave a Comment