Example usage for javax.swing.text DateFormatter setAllowsInvalid

List of usage examples for javax.swing.text DateFormatter setAllowsInvalid

Introduction

In this page you can find the example usage for javax.swing.text DateFormatter setAllowsInvalid.

Prototype

public void setAllowsInvalid(boolean allowsInvalid) 

Source Link

Document

Sets whether or not the value being edited is allowed to be invalid for a length of time (that is, stringToValue throws a ParseException).

Usage

From source file:dk.dma.epd.shore.gui.views.SendRouteDialog.java

/**
 * Configures the given date picker and associated time spinner
 * /*  ww  w  .j  av a  2  s.c o m*/
 * @param picker
 *            the date picker
 * @param spinner
 *            the time spinner
 */
private void initDatePicker(JXDatePicker picker, JSpinner spinner) {
    picker.setFormats(new SimpleDateFormat("E dd/MM/yyyy"));
    picker.addPropertyChangeListener("date", this);

    DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm");
    DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false);
    formatter.setOverwriteMode(true);
    formatter.setCommitsOnValidEdit(true);
    spinner.setEditor(editor);
    spinner.addChangeListener(new SpinnerChangeListener());
}

From source file:dk.dma.epd.common.prototype.gui.route.RoutePropertiesDialogCommon.java

/**
 * Configures the given date picker and associated time spinner
 * @param picker the date picker//from   www .  ja v a  2 s.com
 * @param spinner the time spinner
 */
private void initDatePicker(JXDatePicker picker, JSpinner spinner) {
    picker.setFormats(new SimpleDateFormat("E dd/MM/yyyy"));
    picker.addPropertyChangeListener("date", this);

    DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm");
    DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter();
    formatter.setAllowsInvalid(false);
    formatter.setOverwriteMode(true);
    formatter.setCommitsOnValidEdit(true);
    spinner.setEditor(editor);
    spinner.addChangeListener(new SpinnerChangeListener());

    // Set the enabled state
    picker.setEnabled(!readOnlyRoute);
    spinner.setEnabled(!readOnlyRoute);
}