Install SpinnerListModel for JSpinner in Java

Description

The following code shows how to install SpinnerListModel for JSpinner.

Example


import java.awt.BorderLayout;
//from   www  .  ja  v  a 2  s .  c  o m
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.SpinnerListModel;


public class Main {
  public static void main(String args[]) {
    JFrame frame = new JFrame("JSpinner Sample");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


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

    frame.add(spinner, BorderLayout.SOUTH);

    frame.setSize(200, 90);
    frame.setVisible(true);
  }
}

The code above generates the following result.

Install SpinnerListModel for JSpinner in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer