javax.swing.SpinnerDateModel Java Examples
The following examples show how to use
javax.swing.SpinnerDateModel.
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 File: DateTimePicker.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
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
Source File: bug8008657.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 #3
Source File: bug6463712.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #4
Source File: bug6463712.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 #5
Source File: bug6463712.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From hottub with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 File: SchedulerUI.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
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 #10
Source File: ComparePanel.java From mvisc with GNU General Public License v3.0 | 5 votes |
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 #11
Source File: bug6463712.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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 #12
Source File: IOStatPostParser.java From nmonvisualizer with Apache License 2.0 | 5 votes |
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 #13
Source File: JSpinnerOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 #14
Source File: JSpinnerOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 #15
Source File: bug6463712.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 #16
Source File: bug6463712.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 #17
Source File: JSpinnerJavaElementTest.java From marathonv5 with Apache License 2.0 | 5 votes |
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 #18
Source File: bug6463712.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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 File: bug6463712.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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 File: PlanManager.java From cropplanning with GNU General Public License v3.0 | 5 votes |
@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 #23
Source File: JSpinnerDateEditor.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
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 #24
Source File: JSpinnerDateEditor.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
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 #25
Source File: JSpinnerDateEditor.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Date getDate() { if (date == null) { return null; } return ((SpinnerDateModel) getModel()).getDate(); }
Example #26
Source File: CalendarSpinner.java From Astrosoft with GNU General Public License v2.0 | 4 votes |
private void createSpinner(){ SpinnerModel model = new SpinnerDateModel(); spinner = new JSpinner(model); spinner.setPreferredSize(spinnerSize); editor = new JSpinner.DateEditor(spinner, dateFormat); spinner.setEditor(editor); spinner.addChangeListener(new ChangeListener(){ public void stateChanged(ChangeEvent e) { selectionChanged(e); } }); }
Example #27
Source File: AbsoluteTimeIntervalPanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
AbsoluteTimeIntervalPanel(NMONVisualizerGui gui) { super(gui); setLayout(new BorderLayout()); add.addActionListener(addInterval); // start and end text boxes with labels, followed by a Add button startLabel = new JLabel("Start:"); startLabel.setHorizontalAlignment(SwingConstants.TRAILING); startLabel.setFont(Styles.LABEL); start = new JSpinner(new SpinnerDateModel(new Date(getDefaultStartTime()), null, null, Calendar.MINUTE)); start.setEditor(new DateEditor(start, Styles.DATE_FORMAT_STRING_WITH_YEAR)); start.addChangeListener(intervalUpdater); endLabel = new JLabel("End:"); endLabel.setHorizontalAlignment(SwingConstants.TRAILING); endLabel.setFont(Styles.LABEL); end = new JSpinner(new SpinnerDateModel(new Date(getDefaultEndTime()), null, null, Calendar.MINUTE)); end.setEditor(new DateEditor(end, Styles.DATE_FORMAT_STRING_WITH_YEAR)); end.addChangeListener(intervalUpdater); JPanel namePanel = new JPanel(); namePanel.add(nameLabel); namePanel.add(name); JPanel startPanel = new JPanel(); startPanel.add(startLabel); startPanel.add(start); JPanel endPanel = new JPanel(); endPanel.add(endLabel); endPanel.add(end); JPanel buttonsPanel = new JPanel(); buttonsPanel.add(add); buttonsPanel.add(endToStart); buttonsPanel.add(reset); JPanel dataPanel = new JPanel(); dataPanel.setLayout(new GridBagLayout()); GridBagConstraints labelConstraints = new GridBagConstraints(); GridBagConstraints fieldConstraints = new GridBagConstraints(); labelConstraints.gridx = 0; fieldConstraints.gridx = 1; labelConstraints.gridy = 0; fieldConstraints.gridy = 0; labelConstraints.insets = new Insets(0, 0, 0, 5); fieldConstraints.insets = new Insets(5, 0, 0, 5); labelConstraints.fill = GridBagConstraints.HORIZONTAL; fieldConstraints.fill = GridBagConstraints.HORIZONTAL; dataPanel.add(startLabel, labelConstraints); dataPanel.add(start, fieldConstraints); ++labelConstraints.gridy; ++fieldConstraints.gridy; dataPanel.add(endLabel, labelConstraints); dataPanel.add(end, fieldConstraints); add(namePanel, BorderLayout.PAGE_START); add(dataPanel, BorderLayout.CENTER); add(buttonsPanel, BorderLayout.PAGE_END); }
Example #28
Source File: RelativeTimeIntervalPanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { // all but timeZone fired by IntervalDocumentListeners if ("interval".equals(evt.getPropertyName())) { if (evt.getNewValue() == null) { startLabel.setFont(Styles.LABEL_ERROR); endLabel.setFont(Styles.LABEL_ERROR); startLabel.setForeground(Styles.ERROR_COLOR); endLabel.setForeground(Styles.ERROR_COLOR); start.setForeground(Styles.ERROR_COLOR); end.setForeground(Styles.ERROR_COLOR); days.setForeground(Styles.ERROR_COLOR); } else { startLabel.setFont(Styles.LABEL); endLabel.setFont(Styles.LABEL); startLabel.setForeground(Styles.DEFAULT_COLOR); endLabel.setForeground(Styles.DEFAULT_COLOR); start.setForeground(Styles.DEFAULT_COLOR); end.setForeground(Styles.DEFAULT_COLOR); days.setForeground(Styles.DEFAULT_COLOR); } } else if ("start".equals(evt.getPropertyName())) { startAbsolute.setText(FORMAT.format(new Date((Long) evt.getNewValue()))); } else if ("end".equals(evt.getPropertyName())) { endAbsolute.setText(FORMAT.format(new Date((Long) evt.getNewValue()))); } else if ("timeZone".equals(evt.getPropertyName())) { TimeZone timeZone = (TimeZone) evt.getNewValue(); DateEditor de = (DateEditor) base.getEditor(); de.getFormat().setTimeZone(timeZone); // hack to get the spinner to fire a state change and update the displayed value // toggle the calendar field back to its original value ((SpinnerDateModel) base.getModel()).setCalendarField(Calendar.MINUTE); ((SpinnerDateModel) base.getModel()).setCalendarField(Calendar.SECOND); FORMAT.setTimeZone(timeZone); startAbsolute.setText(FORMAT.format(new Date(getStartTime()))); endAbsolute.setText((FORMAT.format(new Date(getEndTime())))); } }
Example #29
Source File: BulkIntervalPanel.java From nmonvisualizer with Apache License 2.0 | 4 votes |
@Override public void propertyChange(PropertyChangeEvent evt) { if ("timeZone".equals(evt.getPropertyName())) { TimeZone timeZone = (TimeZone) evt.getNewValue(); DateEditor de = (DateEditor) start.getEditor(); de.getFormat().setTimeZone(timeZone); // hack to get the spinner to fire a state change and update the displayed value // toggle the calendar field back to its original value ((SpinnerDateModel) start.getModel()).setCalendarField(Calendar.MINUTE); ((SpinnerDateModel) start.getModel()).setCalendarField(Calendar.SECOND); FORMAT.setTimeZone(timeZone); end.setText(FORMAT.format(getEndTime())); } else if ("values".equals(evt.getPropertyName())) { long[] updatedValues = (long[]) evt.getNewValue(); boolean validDuration = true; // 0 days, then duration must be valid & non-zero if (updatedValues[1] == 0) { // duration if (updatedValues[0] < 1) { validDuration = false; } } if (validDuration) { durationLabel.setFont(Styles.LABEL); durationLabel.setForeground(Styles.DEFAULT_COLOR); duration.setForeground(Styles.DEFAULT_COLOR); days.setForeground(Styles.DEFAULT_COLOR); } else { durationLabel.setFont(Styles.LABEL_ERROR); durationLabel.setForeground(Styles.ERROR_COLOR); duration.setForeground(Styles.ERROR_COLOR); days.setForeground(Styles.ERROR_COLOR); } // repeat if (updatedValues[2] == 0) { repeatLabel.setFont(Styles.LABEL_ERROR); repeatLabel.setForeground(Styles.ERROR_COLOR); repeat.setForeground(Styles.ERROR_COLOR); offset.setEnabled(false); } else { repeatLabel.setFont(Styles.LABEL); repeatLabel.setForeground(Styles.DEFAULT_COLOR); repeat.setForeground(Styles.DEFAULT_COLOR); if (updatedValues[2] == 1) { // repeating once => no offset offset.setEnabled(false); } else { offset.setEnabled(true); } } // offset: -1 => invalid if (updatedValues[3] < 0) { offsetLabel.setFont(Styles.LABEL_ERROR); offsetLabel.setForeground(Styles.ERROR_COLOR); offset.setForeground(Styles.ERROR_COLOR); } else { offsetLabel.setFont(Styles.LABEL); offsetLabel.setForeground(Styles.DEFAULT_COLOR); offset.setForeground(Styles.DEFAULT_COLOR); } // end time if (updatedValues[4] != -1) { end.setText(FORMAT.format(updatedValues[4])); } } }
Example #30
Source File: JSpinnerOperator.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private DateSpinnerOperator(JSpinnerOperator spinner) { super((JSpinner) spinner.getSource()); copyEnvironment(spinner); checkModel(this, SpinnerDateModel.class); }