Java Code Examples for javax.swing.SpinnerDateModel

The following examples show how to use javax.swing.SpinnerDateModel. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: snap-desktop   Source File: DateTimePicker.java    License: GNU General Public License v3.0 6 votes vote down vote up
private JPanel createTimePanel() {
    JPanel newPanel = new JPanel();
    newPanel.setLayout(new FlowLayout());
    Date date = getDate();
    if (date == null) {
        Calendar calendar = Calendar.getInstance(timeZone);
        date = calendar.getTime();
    }
    SpinnerDateModel dateModel = new SpinnerDateModel(date, null, null, Calendar.DAY_OF_MONTH);
    timeSpinner = new JSpinner(dateModel);
    if (timeFormat == null) {
        timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT);
    }
    updateTextFieldFormat();
    newPanel.add(new JLabel("Time:"));
    newPanel.add(timeSpinner);
    newPanel.setBackground(Color.WHITE);
    return newPanel;
}
 
Example 2
public JSpinnerDateEditor() {
	super(new SpinnerDateModel());
	dateFormatter = (SimpleDateFormat) DateFormat
			.getDateInstance(DateFormat.MEDIUM);
	((JSpinner.DateEditor) getEditor()).getTextField().addFocusListener(
			this);
	DateUtil dateUtil = new DateUtil();
	setMinSelectableDate(dateUtil.getMinSelectableDate());
	setMaxSelectableDate(dateUtil.getMaxSelectableDate());
	((JSpinner.DateEditor)getEditor()).getTextField().setFocusLostBehavior(JFormattedTextField.PERSIST);
	addChangeListener(this);
}
 
Example 3
@Override
public Date getDate() {
	if (date == null) {
		return null;
	}
	return ((SpinnerDateModel) getModel()).getDate();
}
 
Example 4
public void setDate(Date date, boolean updateModel) {
	Date oldDate = this.date;
	this.date = date;
	if (date == null) {
		((JSpinner.DateEditor) getEditor()).getFormat().applyPattern("");
		((JSpinner.DateEditor) getEditor()).getTextField().setText("");
	} else if (updateModel) {
		if (dateFormatString != null) {
			((JSpinner.DateEditor) getEditor()).getFormat().applyPattern(
					dateFormatString);
		}
		((SpinnerDateModel) getModel()).setValue(date);
	}
	firePropertyChange("date", oldDate, date);
}
 
Example 5
Source Project: dragonwell8_jdk   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 6
Source Project: TencentKona-8   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 7
Source Project: jdk8u60   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 8
Source Project: openjdk-jdk8u   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 9
Source Project: marathonv5   Source File: JSpinnerJavaElementTest.java    License: Apache License 2.0 5 votes vote down vote up
private JSpinner createDateSpinner(Calendar calendar) {
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -100);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 200);
    Date latestDate = calendar.getTime();
    SpinnerDateModel spinnerDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
    JSpinner dateSpinner = new JSpinner(spinnerDateModel);
    dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MM/yyyy"));
    dateSpinner.setName("date-spinner");
    return dateSpinner;
}
 
Example 10
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 11
Source Project: openjdk-jdk9   Source File: bug8008657.java    License: GNU General Public License v2.0 5 votes vote down vote up
static void createDateSpinner() {
    Calendar calendar = Calendar.getInstance();
    Date initDate = calendar.getTime();
    calendar.add(Calendar.YEAR, -1);
    Date earliestDate = calendar.getTime();
    calendar.add(Calendar.YEAR, 1);
    Date latestDate = calendar.getTime();
    SpinnerModel dateModel = new SpinnerDateModel(initDate,
            earliestDate,
            latestDate,
            Calendar.YEAR);
    spinner = new JSpinner();
    spinner.setModel(dateModel);
}
 
Example 12
Source Project: openjdk-jdk9   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 13
/**
 * Returns a minimal value. Returns null if model is not one of the
 * following: {@code javax.swing.SpinnerDateModel},
 * {@code javax.swing.SpinnerListModel},
 * {@code javax.swing.SpinnerNumberModel}. Also, returns null if the
 * model does not have a minimal value.
 *
 * @return a minimal value.
 */
public Object getMinimum() {
    SpinnerModel model = getModel();
    if (model instanceof SpinnerNumberModel) {
        return ((SpinnerNumberModel) model).getMinimum();
    } else if (model instanceof SpinnerDateModel) {
        return ((SpinnerDateModel) model).getEnd();
    } else if (model instanceof SpinnerListModel) {
        List<?> list = ((SpinnerListModel) model).getList();
        return list.get(list.size() - 1);
    } else {
        return null;
    }
}
 
Example 14
/**
 * Returns a maximal value. Returns null if model is not one of the
 * following: {@code javax.swing.SpinnerDateModel},
 * {@code javax.swing.SpinnerListModel},
 * {@code javax.swing.SpinnerNumberModel}. Also, returns null if the
 * model does not have a maximal value.
 *
 * @return a maximal value.
 */
public Object getMaximum() {
    SpinnerModel model = getModel();
    if (model instanceof SpinnerNumberModel) {
        return ((SpinnerNumberModel) model).getMaximum();
    } else if (model instanceof SpinnerDateModel) {
        return ((SpinnerDateModel) model).getEnd();
    } else if (model instanceof SpinnerListModel) {
        List<?> list = ((SpinnerListModel) model).getList();
        return list.get(list.size() - 1);
    } else {
        return null;
    }
}
 
Example 15
Source Project: mvisc   Source File: ComparePanel.java    License: GNU General Public License v3.0 5 votes vote down vote up
public ComparePanel()
{
	dateSpinner = new JSpinner( new SpinnerDateModel() );
	JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(dateSpinner, "dd.MM.yyyy");
	dateSpinner.setEditor(dateEditor);
	dateSpinner.setValue(new Date()); 
	timeSpinner = new JSpinner( new SpinnerDateModel() );
	JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "HH:mm:ss");
	timeSpinner.setEditor(timeEditor);
	timeSpinner.setValue(new Date()); 
	
}
 
Example 16
private void initDateModel() {
    SpinnerDateModel dmodel = new SpinnerDateModel();
    dateSpinner.setModel(dmodel);
    dateSpinner.setEditor(new JSpinner.DateEditor(dateSpinner, "MMM - dd - yyyy"));

    SpinnerDateModel tmodel = new SpinnerDateModel();
    timeSpinner.setModel(tmodel);
    timeSpinner.setEditor(new JSpinner.DateEditor(timeSpinner, "HH:mm"));
}
 
Example 17
Source Project: jdk8u-jdk   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 18
Source Project: hottub   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 19
Source Project: openjdk-8-source   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 20
Source Project: openjdk-8   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 21
Source Project: jdk8u_jdk   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 22
Source Project: jdk8u-jdk   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 23
Source Project: jdk8u-dev-jdk   Source File: bug6463712.java    License: GNU General Public License v2.0 5 votes vote down vote up
public bug6463712() {
    SpinnerNumberModel m1 = new SpinnerNumberModel();
    JSpinner s = new JSpinner(m1);
    s.addChangeListener(this);
    SpinnerDateModel m2 = new SpinnerDateModel();
    s.setModel(m2);

    // m1 is no longer linked to the JSpinner (it has been replaced by m2), so
    // the following should not trigger a call to our stateChanged() method...
    m1.setValue(new Integer(1));
}
 
Example 24
Source Project: nmonvisualizer   Source File: IOStatPostParser.java    License: Apache License 2.0 5 votes vote down vote up
protected void addComponents(JPanel content, GridBagConstraints labelConstraints,
        GridBagConstraints fieldConstraints) {

    date = new JSpinner(new SpinnerDateModel(new Date(TimeHelper.today()), null, null, Calendar.DAY_OF_WEEK));
    date.setEditor(new DateEditor(date, "MMM dd yyyy"));

    JLabel dateLabel = new JLabel("Date:");
    dateLabel.setFont(Styles.LABEL);
    dateLabel.setHorizontalAlignment(SwingConstants.TRAILING);

    content.add(dateLabel, labelConstraints);
    content.add(date, fieldConstraints);
}
 
Example 25
Source Project: cropplanning   Source File: PlanManager.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void buildContentsPanel() {
   
   cmboPlanList = new JComboBox();
   cmboPlanList.setEditable(true);
   cmboPlanList.addActionListener(this);
   
   spnYear = new JSpinner();
   SpinnerDateModel spnMod = new SpinnerDateModel();
   spnMod.setCalendarField( Calendar.YEAR );
   spnYear.setModel( spnMod );
   spnYear.setEditor( new JSpinner.DateEditor( spnYear, "yyyy" ) );

   spnYear.setPreferredSize( new Dimension( 70, 
                                            spnYear.getPreferredSize().height ));
   tfldDesc = new JTextField( 20 );
   
   JPanel jplCont = new JPanel( new MigLayout( "gapy 0px!, insets 2px", "[align right][]") );
     
   jplCont.add( new JLabel( "Plan:" ) );
   jplCont.add( cmboPlanList, "wrap" );
   jplCont.add( new JLabel( "Year:" ) );
   jplCont.add( spnYear, "wrap" );
   jplCont.add( new JLabel( "Description:" ) );
   jplCont.add( tfldDesc, "wrap" );
   
   jplCont.setBorder( BorderFactory.createEmptyBorder( 10, 10, 0, 10));

   contentsPanelBuilt = true;
   add( jplCont );
   
}
 
Example 26
@Override
public Date getMaxSelectableDate() {
	return (Date) ((SpinnerDateModel) getModel()).getEnd();
}
 
Example 27
/**
 * 
 */
       @Override
public Date getMinSelectableDate() {
	return (Date) ((SpinnerDateModel) getModel()).getStart();
}
 
Example 28
/**
 * 
 */
       @Override
public void setMaxSelectableDate(Date max) {
	((SpinnerDateModel) getModel()).setEnd(max);
}
 
Example 29
/**
 * 
 */
       @Override
public void setMinSelectableDate(Date min) {
	((SpinnerDateModel) getModel()).setStart(min);
}
 
Example 30
/**
 * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
 */
       @Override
public void stateChanged(ChangeEvent e) {
	setDate(((SpinnerDateModel) getModel()).getDate(), false);
}