Example usage for javax.swing JFormattedTextField COMMIT_OR_REVERT

List of usage examples for javax.swing JFormattedTextField COMMIT_OR_REVERT

Introduction

In this page you can find the example usage for javax.swing JFormattedTextField COMMIT_OR_REVERT.

Prototype

int COMMIT_OR_REVERT

To view the source code for javax.swing JFormattedTextField COMMIT_OR_REVERT.

Click Source Link

Document

Constant identifying that when focus is lost, commitEdit should be invoked.

Usage

From source file:org.revager.tools.GUITools.java

/**
 * Formats the given spinner.//from  w  w w . j  a v  a  2s.  c o  m
 * 
 * @param sp
 *            the spinner
 */
public static void formatSpinner(JSpinner sp, boolean hideBorder) {
    JSpinner.DefaultEditor defEditor = (JSpinner.DefaultEditor) sp.getEditor();
    JFormattedTextField ftf = defEditor.getTextField();
    ftf.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
    InternationalFormatter intFormatter = (InternationalFormatter) ftf.getFormatter();
    DecimalFormat decimalFormat = (DecimalFormat) intFormatter.getFormat();
    decimalFormat.applyPattern("00");
    DecimalFormatSymbols geSymbols = new DecimalFormatSymbols(Data.getInstance().getLocale());
    decimalFormat.setDecimalFormatSymbols(geSymbols);

    if (hideBorder) {
        sp.setBorder(null);
    }
}