Java JSpinner .setModel (SpinnerModel model)
Syntax
JSpinner.setModel(SpinnerModel model) has the following syntax.
public void setModel(SpinnerModel model)
Example
In the following code shows how to use JSpinner.setModel(SpinnerModel model) method.
// ww w . j a v a2 s . co m
import java.awt.Container;
import java.awt.FlowLayout;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerDateModel;
public class Main extends JFrame {
public Main() {
super("Month Spinner");
setSize(200, 100);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container c = getContentPane();
c.setLayout(new FlowLayout(FlowLayout.LEFT, 4, 4));
c.add(new JLabel("Expiration Date:"));
Date today = new Date();
SpinnerDateModel model = new SpinnerDateModel(today, null, null, Calendar.MONTH);
JSpinner s = new JSpinner();
s.setModel(model);
JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
s.setEditor(de);
c.add(s);
setVisible(true);
}
public static void main(String args[]) {
new Main();
}
}
Home »
Java Tutorial »
javax.swing »
Java Tutorial »
javax.swing »