Package javax.swing.text

Examples of javax.swing.text.NumberFormatter


        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 2;
        inputPanel2.add(queryButton, c);

        maxHitsField = new JFormattedTextField(new NumberFormatter());
        maxHitsField.setValue(Integer.valueOf(100));
        maxHitsField.setColumns(5);

        JLabel maxHitsLabel = new JLabel("Max hits:");
        maxHitsLabel.setLabelFor(maxHitsField);
View Full Code Here


        JLabel levelLabel = new JLabel("Levels: ", JLabel.LEFT);
        levelLabel.setAlignmentX(Component.CENTER_ALIGNMENT);

        java.text.NumberFormat numberFormat =
            java.text.NumberFormat.getIntegerInstance();
        NumberFormatter formatter = new NumberFormatter(numberFormat);
        formatter.setMinimum(new Integer(1));
        formatter.setMaximum(new Integer(10000));
        levelText = new JFormattedTextField(formatter);
        levelText.setValue(new Integer(1));
        levelText.setColumns(3);
        levelText.addActionListener(this);
View Full Code Here

    private void setupNumberFormat() {
        // Determine the number of decimals to show
        NumberFormat fmt = NumberFormat.getNumberInstance();
        fmt.setMinimumFractionDigits( fractionDigits );
        valueField.setFormatterFactory( new DefaultFormatterFactory(
                new NumberFormatter( fmt ) ) );
    }
View Full Code Here

    }
   
    private static NumberFormatter getNumberFormatter() {
       
        DecimalFormat format = new DecimalFormat( "#####" );
        NumberFormatter f = new NumberFormatter( format );
       
        f.setAllowsInvalid( false );
       
        return f;
       
    }
View Full Code Here

            format.setMaximumFractionDigits(0);
            format.setMinimumIntegerDigits(0);
            format.setMaximumIntegerDigits(5);
            format.setParseIntegerOnly(true);
            format.setDecimalSeparatorAlwaysShown(false);
            NumberFormatter nf = new NumberFormatter(format);
            nf.setMinimum(new Integer(1));
            nf.setMaximum(new Integer(Integer.MAX_VALUE));
            nf.setAllowsInvalid(true);
            nf.setCommitsOnValidEdit(true);
            tfRangeFrom = new JFormattedTextField(nf);
            tfRangeFrom.setColumns(4);
            tfRangeFrom.setEnabled(false);
            tfRangeFrom.addActionListener(this);
            tfRangeFrom.addFocusListener(this);
            tfRangeFrom.setFocusLostBehavior(
                JFormattedTextField.PERSIST);
            tfRangeFrom.getAccessibleContext().setAccessibleName(
                                          getMsg("radiobutton.rangepages"));
            pnlBottom.add(tfRangeFrom);
            lblRangeTo = new JLabel(getMsg("label.rangeto"));
            lblRangeTo.setEnabled(false);
            pnlBottom.add(lblRangeTo);
            NumberFormatter nfto;
            try {
                nfto = (NumberFormatter)nf.clone();
            } catch (CloneNotSupportedException e) {
                nfto = new NumberFormatter();
            }
            tfRangeTo = new JFormattedTextField(nfto);
            tfRangeTo.setColumns(4);
            tfRangeTo.setEnabled(false);
            tfRangeTo.addFocusListener(this);
View Full Code Here

            format.setMinimumFractionDigits(1);
            format.setMaximumFractionDigits(2);
            format.setMinimumIntegerDigits(1);
            format.setParseIntegerOnly(false);
            format.setDecimalSeparatorAlwaysShown(true);
            NumberFormatter nf = new NumberFormatter(format);
            nf.setMinimum(new Float(0.0f));
            nf.setMaximum(new Float(999.0f));
            nf.setAllowsInvalid(true);
            nf.setCommitsOnValidEdit(true);

            leftMargin = new JFormattedTextField(nf);
            leftMargin.addFocusListener(this);
            leftMargin.addActionListener(this);
            leftMargin.getAccessibleContext().setAccessibleName(
View Full Code Here

            minimum = Integer.valueOf(min);
            maximum = Integer.valueOf(max);

            // Set up the editor for the integer cells.
            integerFormat = NumberFormat.getIntegerInstance();
            NumberFormatter intFormatter = new NumberFormatter(integerFormat);
            intFormatter.setFormat(integerFormat);
            intFormatter.setMinimum(minimum);
            intFormatter.setMaximum(maximum);

            ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
            ftf.setValue(minimum);
            ftf.setHorizontalAlignment(JTextField.TRAILING);
            ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
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

   
    /*
     * 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

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.