javax.swing.text.DateFormatter Java Examples
The following examples show how to use
javax.swing.text.DateFormatter.
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: DateCellEditor.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public void setDateFormat( final DateFormat timeFormat ) { if ( timeFormat == null ) { throw new NullPointerException(); } dateField.setFormatterFactory( new JFormattedTextField.AbstractFormatterFactory() { public JFormattedTextField.AbstractFormatter getFormatter( final JFormattedTextField tf ) { return new DateFormatter( timeFormat ) { // allow to clear the field public Object stringToValue( final String text ) throws ParseException { return "".equals( text ) ? null : super.stringToValue( text ); } }; } } ); if ( timeFormat instanceof SimpleDateFormat ) { final SimpleDateFormat dateFormat = (SimpleDateFormat) timeFormat; setToolTipText( dateFormat.toLocalizedPattern() ); } else { setToolTipText( null ); } if ( dateChooserPanel != null ) { setDate( getCellEditorValue() ); } }
Example #2
Source File: SimulationParameters.java From High-Frequency-Data-Order-Book-Analyser with GNU General Public License v2.0 | 6 votes |
/** * Creates new form FileSelection */ public SimulationParameters() { initComponents(); this.setResizable(false); this.setTitle("File Selection"); fileReader = new FileRead(); initialiseDateComboBox(fileReader); JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(SpinnerTime, "HH:mm:ss"); DateFormatter formatter = (DateFormatter) timeEditor.getTextField().getFormatter(); formatter.setAllowsInvalid(false); // Make sure no invalid input is allowed SpinnerTime.setEditor(timeEditor); String StartTime = "08:30:00"; Date time; try { time = new SimpleDateFormat("HH:mm:ss").parse(StartTime); SpinnerTime.setValue(time); // will only show the current time } catch (ParseException ex) { Logger.getLogger(SimulationParameters.class.getName()).log(Level.SEVERE, null, ex); } }
Example #3
Source File: DateTimePicker.java From nosql4idea with Apache License 2.0 | 5 votes |
private void updateTextFieldFormat() { if (timeSpinner == null) return; JFormattedTextField tf = ((JSpinner.DefaultEditor) timeSpinner.getEditor()).getTextField(); DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory(); DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter(); // Change the date format to only show the hours formatter.setFormat(timeFormat); }
Example #4
Source File: DateTimePicker.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void updateTextFieldFormat() { if (timeSpinner == null) { return; } JFormattedTextField tf = ((JSpinner.DefaultEditor) timeSpinner.getEditor()).getTextField(); DefaultFormatterFactory factory = (DefaultFormatterFactory) tf.getFormatterFactory(); DateFormatter formatter = (DateFormatter) factory.getDefaultFormatter(); // Change the date format to only show the hours formatter.setFormat(timeFormat); }
Example #5
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private MainPanel() { super(new GridLayout(2, 1)); Calendar c = Calendar.getInstance(); // c.clear(Calendar.HOUR_OF_DAY); // c.clear(Calendar.AM_PM); // c.clear(Calendar.HOUR); c.set(Calendar.HOUR_OF_DAY, 0); c.clear(Calendar.MINUTE); c.clear(Calendar.SECOND); c.clear(Calendar.MILLISECOND); Date d = c.getTime(); SimpleDateFormat format = new SimpleDateFormat("mm:ss", Locale.getDefault()); DefaultFormatterFactory factory = new DefaultFormatterFactory(new DateFormatter(format)); JSpinner spinner1 = new JSpinner(new SpinnerDateModel(d, null, null, Calendar.SECOND)); ((JSpinner.DefaultEditor) spinner1.getEditor()).getTextField().setFormatterFactory(factory); JSpinner spinner2 = new JSpinner(new SpinnerDateModel(d, null, null, Calendar.SECOND) { @Override public void setCalendarField(int calendarField) { // https://docs.oracle.com/javase/8/docs/api/javax/swing/SpinnerDateModel.html#setCalendarField-int- // If you only want one field to spin you can subclass and ignore the setCalendarField calls. } }); ((JSpinner.DefaultEditor) spinner2.getEditor()).getTextField().setFormatterFactory(factory); add(makeTitledPanel("Default SpinnerDateModel", spinner1)); add(makeTitledPanel("Override SpinnerDateModel#setCalendarField(...)", spinner2)); setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5)); setPreferredSize(new Dimension(320, 240)); }
Example #6
Source File: Test6462562.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #7
Source File: BasicDatePickerUI.java From microba with BSD 3-Clause "New" or "Revised" License | 4 votes |
private DefaultFormatterFactory createFormatterFactory() { return new DefaultFormatterFactory(new DateFormatter(peer .getDateFormat())); }
Example #8
Source File: Test6462562.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #9
Source File: Test6462562.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #10
Source File: Test6462562.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #11
Source File: Test6462562.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #12
Source File: Test6462562.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #13
Source File: Test6462562.java From hottub with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #14
Source File: Test6462562.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #15
Source File: Test6462562.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #16
Source File: Test6462562.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #17
Source File: Test6462562.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #18
Source File: Test6462562.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }
Example #19
Source File: Test6462562.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
TestFormattedTextField create(DateFormat format) { DateFormatter fmt = new DateFormatter(format); return new TestFormattedTextField(fmt); }