Example usage for javax.swing SpinnerDateModel setCalendarField

List of usage examples for javax.swing SpinnerDateModel setCalendarField

Introduction

In this page you can find the example usage for javax.swing SpinnerDateModel setCalendarField.

Prototype

public void setCalendarField(int calendarField) 

Source Link

Document

Changes the size of the date value change computed by the nextValue and previousValue methods.

Usage

From source file:Main.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Spinning");
    Container contentPane = frame.getContentPane();
    String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };
    SpinnerModel model = new SpinnerListModel(months);
    JSpinner spinner = new JSpinner(model);
    contentPane.add(spinner, BorderLayout.NORTH);

    SpinnerDateModel model2 = new SpinnerDateModel();
    model2.setCalendarField(Calendar.WEEK_OF_MONTH);
    JSpinner spinner2 = new JSpinner(model2);
    JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy");
    spinner2.setEditor(editor2);/*from   w  ww  .j  ava 2  s. c  o m*/
    frame.getContentPane().add(spinner2, BorderLayout.CENTER);

    SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5);
    JSpinner spinner3 = new JSpinner(model3);
    frame.getContentPane().add(spinner3, BorderLayout.SOUTH);

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

From source file:SpinnerTest.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Spinning");
    Container contentPane = frame.getContentPane();
    String months[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
            "October", "November", "December" };
    SpinnerModel model = new SpinnerListModel(months);
    JSpinner spinner = new JSpinner(model);
    contentPane.add(spinner, BorderLayout.NORTH);

    SpinnerDateModel model2 = new SpinnerDateModel();
    model2.setCalendarField(Calendar.WEEK_OF_MONTH);
    JSpinner spinner2 = new JSpinner(model2);
    JSpinner.DateEditor editor2 = new JSpinner.DateEditor(spinner2, "MMMMM dd, yyyy");
    spinner2.setEditor(editor2);//from  ww  w. j a v a  2  s. c o  m
    frame.getContentPane().add(spinner2, BorderLayout.CENTER);

    SpinnerNumberModel model3 = new SpinnerNumberModel(50, 0, 100, 5);
    JSpinner spinner3 = new JSpinner(model3);
    frame.getContentPane().add(spinner3, BorderLayout.SOUTH);

    frame.setSize(200, 100);
    frame.show();
}

From source file:net.sf.housekeeper.swing.util.BoundComponentFactory.java

/**
 * Creates a JSpinner whose value is bound to the given ValueModel. This
 * means, that the value of the spinner and the value of the ValueModel are
 * synchronized bidirectionally. Additionally, the spinner uses
 * the current locale's short format for displaying a date.
 * /*www .  j  a v a  2s . c  o m*/
 * @param valueModel the model that provides the value. Must not be null and
 *            must provide {@link Date}objects.
 * @return A spinner whose value is bound to <code>valueModel</code>.
 */
public static JSpinner createDateSpinner(final ValueModel valueModel) {
    assert valueModel != null : "Parameter valueModel must not be null";
    assert valueModel.getValue().getClass()
            .equals(Date.class) : "valueModel must provide Date objects as values";

    final SpinnerDateModel model = new SpinnerDateModelAdapter(valueModel);
    //Need to truncate the current date for correct spinner operation
    model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH));
    model.setCalendarField(Calendar.DAY_OF_MONTH);

    final JSpinner spinner = new JSpinner(model);

    //Set the spinner's editor to use the current locale's short date
    // format
    final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT);
    final String formatPattern = dateFormat.toPattern();
    spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern));

    return spinner;
}

From source file:net.sf.housekeeper.swing.FoodEditorView.java

/**
 * Creates a JSpinner which uses the current locale's short format for
 * displaying a date. It's default date date is set to today's date.
 * //from www.ja va2  s. c  o  m
 * @return The created spinner.
 */
private JSpinner createDateSpinner() {
    final SpinnerDateModel model = new SpinnerDateModel();

    //Need to truncate the current date for correct spinner operation
    model.setStart(DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH));
    model.setCalendarField(Calendar.DAY_OF_MONTH);

    final JSpinner spinner = new JSpinner(model);

    //Set the spinner's editor to use the current locale's short date
    // format
    final SimpleDateFormat dateFormat = (SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.SHORT);
    final String formatPattern = dateFormat.toPattern();
    spinner.setEditor(new JSpinner.DateEditor(spinner, formatPattern));

    return spinner;
}