Package javax.swing.text

Examples of javax.swing.text.NumberFormatter


    private boolean updateMargins() {
        float x1;
        float y1;
        float x2;
        float y2;   
        NumberFormatter format = getFloatFormatter();
   
        if (!leftTxt.isEnabled()) {
            removeAttribute(MediaPrintableArea.class);
            removeAttribute(MediaMargins.class);
            return true;
        }
   
        try {
            x1 = ((Float) format.stringToValue(leftTxt.getText())).floatValue();
            x2 = ((Float) format.stringToValue(rightTxt.getText())).floatValue();
            y1 = ((Float) format.stringToValue(topTxt.getText())).floatValue();
            y2 = ((Float) format.stringToValue(bottomTxt.getText())).floatValue();
        } catch(ParseException e) {
            return false;
        }
   
        if (sizeBox.isEnabled()
View Full Code Here


   
    /*
     * Set Margins dialog fields in accordance with the given MediaMargins object
    */
    private void setMargins(MediaMargins margins) {
        NumberFormatter fmt = getFloatFormatter();
        try {
            leftTxt.setText(fmt.valueToString(
                    new Float(margins.getX1(MediaMargins.MM))));
            rightTxt.setText(fmt.valueToString(
                    new Float(margins.getX2(MediaMargins.MM))));
            topTxt.setText(fmt.valueToString(
                    new Float(margins.getY1(MediaMargins.MM))));
            bottomTxt.setText(fmt.valueToString(
                    new Float(margins.getY2(MediaMargins.MM))));
        } catch (ParseException e) {
            /* Ignore incorrect float format */
        }
    }
View Full Code Here

    private boolean updateMargins() {
        float x1;
        float y1;
        float x2;
        float y2;   
        NumberFormatter format = getFloatFormatter();
   
        if (!leftTxt.isEnabled()) {
            removeAttribute(MediaPrintableArea.class);
            removeAttribute(MediaMargins.class);
            return true;
        }
   
        try {
            x1 = ((Float) format.stringToValue(leftTxt.getText())).floatValue();
            x2 = ((Float) format.stringToValue(rightTxt.getText())).floatValue();
            y1 = ((Float) format.stringToValue(topTxt.getText())).floatValue();
            y2 = ((Float) format.stringToValue(bottomTxt.getText())).floatValue();
        } catch(ParseException e) {
            return false;
        }
   
        if (sizeBox.isEnabled()
View Full Code Here

   
    /*
     * Set Margins dialog fields in accordance with the given MediaMargins object
    */
    private void setMargins(MediaMargins margins) {
        NumberFormatter fmt = getFloatFormatter();
        try {
            leftTxt.setText(fmt.valueToString(
                    new Float(margins.getX1(MediaMargins.MM))));
            rightTxt.setText(fmt.valueToString(
                    new Float(margins.getX2(MediaMargins.MM))));
            topTxt.setText(fmt.valueToString(
                    new Float(margins.getY1(MediaMargins.MM))));
            bottomTxt.setText(fmt.valueToString(
                    new Float(margins.getY2(MediaMargins.MM))));
        } catch (ParseException e) {
            /* Ignore incorrect float format */
        }
    }
View Full Code Here

    private boolean updateMargins() {
        float x1;
        float y1;
        float x2;
        float y2;   
        NumberFormatter format = getFloatFormatter();
   
        if (!leftTxt.isEnabled()) {
            removeAttribute(MediaPrintableArea.class);
            removeAttribute(MediaMargins.class);
            return true;
        }
   
        try {
            x1 = ((Float) format.stringToValue(leftTxt.getText())).floatValue();
            x2 = ((Float) format.stringToValue(rightTxt.getText())).floatValue();
            y1 = ((Float) format.stringToValue(topTxt.getText())).floatValue();
            y2 = ((Float) format.stringToValue(bottomTxt.getText())).floatValue();
        } catch(ParseException e) {
            return false;
        }
   
        if (sizeBox.isEnabled()
View Full Code Here

/*
* Formatter for the integer text fields
*/
public static NumberFormatter getNumberFormatter() {
    DecimalFormat format = new DecimalFormat("#####");
    NumberFormatter ret;
    format.setParseIntegerOnly(true);
    format.setDecimalSeparatorAlwaysShown(false);
    format.setMinimumIntegerDigits(0);
    format.setMaximumIntegerDigits(5);
    format.setMinimumFractionDigits(0);
    format.setMaximumFractionDigits(0);
    ret = new NumberFormatter(format);
    ret.setMinimum(new Integer(1));
    ret.setMaximum(new Integer(Integer.MAX_VALUE));
    return ret;
}
View Full Code Here

/*
* Formatter for the float text fields
*/
public static NumberFormatter getFloatFormatter() {
    DecimalFormat format = new DecimalFormat("###.##");
    NumberFormatter ret;
    format.setParseIntegerOnly(false);
    format.setDecimalSeparatorAlwaysShown(true);
    format.setMinimumIntegerDigits(1);
    format.setMaximumIntegerDigits(3);
    format.setMinimumFractionDigits(1);
    format.setMaximumFractionDigits(2);
    ret = new NumberFormatter(format);
    ret.setMinimum(new Float(0.0F));
    ret.setMaximum(new Float(999F));
    return ret;
}
View Full Code Here

    }

    private AbstractFormatterFactory createFactory(final Object value) {
        DefaultFormatterFactory factory = new DefaultFormatterFactory();
        if (value instanceof Number) {
            factory.setDefaultFormatter(new NumberFormatter());
        } else if (value instanceof Date) {
            factory.setDefaultFormatter(new DateFormatter());
        } else {
            factory.setDefaultFormatter(new DefaultFormatter());
        }
View Full Code Here

    private AbstractFormatter createFormatter(final Format format) {
        if (format instanceof DateFormat) {
            return new DateFormatter((DateFormat) format);
        } else if (format instanceof NumberFormat) {
            return new NumberFormatter((NumberFormat) format);
        } else {
            return new InternationalFormatter(format);
        }
    }
View Full Code Here

    // use a custom formatter to have numbers with up to 64 decimals
    NumberFormat format = NumberConverters.getDefaultFormat();

    ((JFormattedTextField) editor).setFormatterFactory(
        new DefaultFormatterFactory(new NumberFormatter(format))
    );
  }
View Full Code Here

TOP

Related Classes of javax.swing.text.NumberFormatter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.