Package javax.swing.text

Examples of javax.swing.text.NumberFormatter


        StringBuilder numberFormatString = new StringBuilder();
        numberFormatString.append("0").append((decimalPlaces > 0? "." : ""));
        for (int i = 0; i < decimalPlaces; i++) {
            numberFormatString.append("0");
        }
        nf = new NumberFormatter(new DecimalFormat(numberFormatString.toString()));
    }
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

        assertTrue(commitAction instanceof TextAction);
        //TODO check commit & cancel actions
    }

    public void testCommitEdit() {
        tf.setFormatter(new NumberFormatter());
        assertNull(tf.getValue());
        tf.setText("678");
        try {
            tf.commitEdit();
        } catch (ParseException e) {
View Full Code Here

    public void testNumberEditor_formatter() {
        NumberEditor numEditor = new NumberEditor(spinner);
        spinner.setEditor(numEditor);
        final Integer max1 = new Integer(777);
        NumberFormatter numberFormatter = ((NumberFormatter) numEditor.getTextField()
                .getFormatter());
        numberFormatter.setMaximum(max1);
        assertSame(numberFormatter.getMaximum(), max1);
        assertSame(numEditor.getModel().getMaximum(), max1);
        final Integer max2 = new Integer(555);
        numEditor.getModel().setMaximum(max2);
        assertSame(numberFormatter.getMaximum(), max2);
        assertSame(numEditor.getModel().getMaximum(), max2);
        SpinnerNumberModel old = (SpinnerNumberModel) spinner.getModel();
        spinner.setModel(abstractModel);
        final Integer max3 = new Integer(333);
        old.setMaximum(max3);
View Full Code Here

    public String convertCal4String(Calendar cal)
            throws ICalendarServiceException {
        DecimalFormat yformat = new DecimalFormat("0000");
        DecimalFormat format = new DecimalFormat("00");
        NumberFormatter formatter = new NumberFormatter();

        try {
            formatter.setFormat(yformat);
            String year = formatter.valueToString(new Integer(cal.get(Calendar.YEAR)));
            formatter.setFormat(format);
            String month = formatter.valueToString(new Integer(cal.get(Calendar.MONTH) + 1));
            String day = formatter.valueToString(new Integer(cal.get(Calendar.DAY_OF_MONTH)));

            return year + month + day;
        } catch (ParseException e) {
            logger.error("Error during parsing.", e);
            throw new ICalendarServiceException(
View Full Code Here

          txtSearchField.setVisible(false);
          NumberFormat mzFormatter = MZmineCore.getConfiguration()
              .getMZFormat();
          Range mzRange = peakList.getRowsMZRange();
          DefaultFormatterFactory mzFormatFac = new DefaultFormatterFactory(
              new NumberFormatter(mzFormatter));
          minSearchField.setFormatterFactory(mzFormatFac);
          minSearchField.setValue(mzRange.getMin());
          maxSearchField.setFormatterFactory(mzFormatFac);
          maxSearchField.setValue(mzRange.getMax());
          break;

        case RT :
          minSearchField.setVisible(true);
          maxSearchField.setVisible(true);
          labelRange.setVisible(true);
          txtSearchField.setVisible(false);
          NumberFormat rtFormatter = MZmineCore.getConfiguration()
              .getRTFormat();
          Range rtRange = peakList.getRowsRTRange();
          DefaultFormatterFactory rtFormatFac = new DefaultFormatterFactory(
              new NumberFormatter(rtFormatter));
          minSearchField.setFormatterFactory(rtFormatFac);
          minSearchField.setValue(rtRange.getMin());
          maxSearchField.setFormatterFactory(rtFormatFac);
          maxSearchField.setValue(rtRange.getMax());
          break;
View Full Code Here

    maxTxtField.removePropertyChangeListener(property, listener);
  }

  public void setNumberFormat(NumberFormat format) {
    DefaultFormatterFactory fac = new DefaultFormatterFactory(
        new NumberFormatter(format));
    minTxtField.setFormatterFactory(fac);
    maxTxtField.setFormatterFactory(fac);
  }
View Full Code Here

        jPanel3.setPreferredSize(new Dimension(500, 380));

        jLabel3.setText(NbBundle.getMessage(ConfigDialog.class, "ConfigDialog.jLabel1.text")); // NOI18N

        defaultThrottleTextBox1.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(new DecimalFormat("#0"))));

        Binding binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, ELProperty.create("${globalConfig[\"profile.defaultThrottle\"]}"), defaultThrottleTextBox1, BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        jLabel4.setText(NbBundle.getMessage(ConfigDialog.class, "ConfigDialog.jLabel2.text")); // NOI18N
View Full Code Here

    // End of variables declaration//GEN-END:variables
   
    private static class IntegerFormatterFactory extends AbstractFormatterFactory {
        @Override
        public AbstractFormatter getFormatter(JFormattedTextField tf) {
            NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0"));
            formatter.setValueClass(Integer.class);
            formatter.setAllowsInvalid(true);
            formatter.setCommitsOnValidEdit(false);
            formatter.setMinimum(0);
            return formatter;
        };
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.