Example usage for javax.swing.text DateFormatter setOverwriteMode

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

Introduction

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

Prototype

public void setOverwriteMode(boolean overwriteMode) 

Source Link

Document

Configures the behavior when inserting characters.

Usage

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

/**
 * Configures the given date picker and associated time spinner
 * /*from  w w  w.jav  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   w  w  w  . ja  va  2 s  .  c  o  m*/
 * @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);
}