Examples of NumberFormatter


Examples of javax.swing.text.NumberFormatter

    JSpinner s = new JSpinner();
    JSpinner.NumberEditor e = new JSpinner.NumberEditor(s);
    harness.check(e.getLayout(), e);
    harness.check(e.getFormat(), NumberFormat.getInstance());
    JFormattedTextField ftf = e.getTextField();
    NumberFormatter nf = (NumberFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), null);
    harness.check(nf.getMaximum(), null);
   
    SpinnerNumberModel m = new SpinnerNumberModel(50.0, 0.0, 100.0, 5.0);
    s = new JSpinner(m);
    e = new JSpinner.NumberEditor(s);
    harness.check(e.getFormat(), NumberFormat.getInstance());
    ftf = e.getTextField();
    nf = (NumberFormatter) ftf.getFormatter();
    harness.check(nf.getMinimum(), new Double(0.0));
    harness.check(nf.getMaximum(), new Double(100.0));
   
    // try null argument
    boolean pass = false;
    try
      {
View Full Code Here

Examples of javax.swing.text.NumberFormatter

    final JPanel pnlLocalPeer = new JPanel();
    pnlLocalPeer
        .setLayout(new BoxLayout(pnlLocalPeer, BoxLayout.PAGE_AXIS));
    pnlLocalPeer.add(new JLabel("Select port where to start peer:"));
    final JFormattedTextField localPort = new JFormattedTextField(
        new NumberFormatter());
    localPort.setValue(11111);
    pnlLocalPeer.add(localPort);
    final JPanel pnlMasterPeer = new JPanel();
    pnlMasterPeer.setLayout(new BoxLayout(pnlMasterPeer,
        BoxLayout.PAGE_AXIS));
    final JCheckBox connectMaster = new JCheckBox(
        "Should be connected with master peer?");
    pnlMasterPeer.add(connectMaster);
    final JPanel masterConfiguration = new JPanel();
    masterConfiguration.setLayout(new BoxLayout(masterConfiguration,
        BoxLayout.PAGE_AXIS));
    masterConfiguration.setVisible(false);
    pnlMasterPeer.add(masterConfiguration);
    connectMaster.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(final ActionEvent arg0) {
        //show master-configuration only if is to be connected to master peer
        masterConfiguration.setVisible(connectMaster.isSelected());
      }
    });
    masterConfiguration
        .add(new JLabel("Select master-port to connect to:"));
    final JFormattedTextField masterPort = new JFormattedTextField(
        new NumberFormatter());
    masterPort.setValue(11111);
    masterConfiguration.add(masterPort);
    masterConfiguration.add(new JLabel(
        "Select master-address/ip to connect to:"));
    final JTextField masterAddress = new JTextField();
View Full Code Here

Examples of javax.swing.text.NumberFormatter

    }

    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

Examples of javax.swing.text.NumberFormatter

    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

Examples of javax.swing.text.NumberFormatter

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

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

Examples of javax.swing.text.NumberFormatter

  private NumberFormat numberFormat = NumberFormat.getIntegerInstance();

  public IntegerField(int min, int max, int initialValue) {
    super();

    NumberFormatter formatter = new NumberFormatter(numberFormat);
    formatter.setMinimum(new Integer(min));
    formatter.setMaximum(new Integer(max));
    formatter.setCommitsOnValidEdit(true);
    setFormatter(formatter);

    setValue(new Integer(initialValue));
  }
View Full Code Here

Examples of javax.swing.text.NumberFormatter

    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

Examples of javax.swing.text.NumberFormatter

        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

Examples of javax.swing.text.NumberFormatter

        if (template == null) {
            dataField.setFormatterFactory(null);
            return;
        }
        NumericFormat nf = new NumericFormat(template, NumericFormat.qq_Resolver.cTEMPLATE);
        DefaultFormatterFactory factory = new DefaultFormatterFactory(new NumberFormatter(nf.getFormatter()), // default
                new NumberFormatter(nf.getFormatter()), // display
                new NumberFormatter(nf.getFormatter()), // edit
                null); // null value
        dataField.setFormatterFactory(factory);
        if (dataField.getTable() != null) {
            JTable table = dataField.getTable();
            ArrayColumn ac = (ArrayColumn) table.getColumnModel().getColumn(dataField.getTableColumn());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.