Example usage for javax.swing.text InternationalFormatter getFormat

List of usage examples for javax.swing.text InternationalFormatter getFormat

Introduction

In this page you can find the example usage for javax.swing.text InternationalFormatter getFormat.

Prototype

public Format getFormat() 

Source Link

Document

Returns the format that dictates the legal values that can be edited and displayed.

Usage

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

/**
 * Formats the given spinner./*ww w  . ja v a  2 s.  co  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);
    }
}