An example of JSpinner with a custom editor : Spinner « Swing JFC « Java






An example of JSpinner with a custom editor

An example of JSpinner with a custom editor
   
/*
Java Swing, 2nd Edition
By Marc Loy, Robert Eckstein, Dave Wood, James Elliott, Brian Cole
ISBN: 0-596-00408-7
Publisher: O'Reilly 
*/
// MonthSpinner.java
//An example of JSpinner with a custom editor that allows the user to spin
//through dates of the mm/yy format.
//

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 MonthSpinner extends JFrame {

  public MonthSpinner() {
    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();
    // Start the spinner today, but don't set a min or max date
    // The increment should be a month
    JSpinner s = new JSpinner(new SpinnerDateModel(today, null, null,
        Calendar.MONTH));
    JSpinner.DateEditor de = new JSpinner.DateEditor(s, "MM/yy");
    s.setEditor(de);
    c.add(s);

    setVisible(true);
  }

  public static void main(String args[]) {
    new MonthSpinner();
  }
}

           
         
    
    
  








Related examples in the same category

1.A program to test spinners.A program to test spinners.
2.An implementation of JSpinner with customized content--iconsAn implementation of JSpinner with customized content--icons
3.A quick test of various spinnersA quick test of various spinners
4.Create a spinnerCreate a spinner
5.Demonstrating the JSpinner ComponentDemonstrating the JSpinner Component
6.Demonstrate the Swing Spinner control
7.Spinner 2Spinner 2
8.Listening for Changes to the Value in a JSpinner Component
9.Creating a SpinnerListModel That Loops Through Its Values
10.Customizing the Editor in a JSpinner Component: Create a color spinner
11.Setting the Margin Space on a JSpinner Component
12.Limiting the Values in a Number JSpinner Component
13.Disabling Keyboard Editing in a JSpinner Component
14.Creating an Hour JSpinner Component
15.Creating a JSpinner Component: A number spinner:
16.A list spinner
17.A date spinner
18.A spinner of dates
19.Use an Icon Editor for use with the JSpinner component
20.Use images in tooltips
21.Number spinner
22.Date spinner
23.List based spinner
24.Java Spinner ComponentJava Spinner Component
25.Enhanced Spinner List Formatter
26.Enhanced Spinner List Model