Java JTextField Number setTextField(javax.swing.JTextField textField, double value, int precision)

Here you can find the source of setTextField(javax.swing.JTextField textField, double value, int precision)

Description

Set a text field with the given value using the given precision.

License

Open Source License

Declaration

public static void setTextField(javax.swing.JTextField textField, double value, int precision) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /** /*from w w w. ja  va 2  s.  c  o  m*/
     * Set a text field with the given value using a precision of 10.
     */
    public static void setTextField(javax.swing.JTextField textField, double value) {
        int precision = 10;

        java.text.NumberFormat nf = java.text.NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(precision);
        nf.setMinimumFractionDigits(precision);
        nf.setGroupingUsed(false);

        textField.setText(nf.format(value));
        textField.setCaretPosition(0);
    }

    /** 
     * Set a text field with the given value using the given precision.
     */
    public static void setTextField(javax.swing.JTextField textField, double value, int precision) {
        java.text.NumberFormat nf = java.text.NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(precision);
        nf.setMinimumFractionDigits(precision);
        nf.setGroupingUsed(false);

        textField.setText(nf.format(value));
        textField.setCaretPosition(0);
    }
}

Related

  1. largeEqualThan(javax.swing.JTextField input, double x)
  2. parseIntFromField(JTextField jField, int pDefault)
  3. placeDoubleTextInField(JTextField inField, int length, double toPlace)
  4. readDoubleFromField(JTextField inField, double defaultValue)
  5. setNumericAndCharOnly(final javax.swing.JTextField textField)
  6. showInDecimalFormat(JTextField pJTextField)
  7. validateDoubleInput(Component parentComponent, JLabel label, JTextField textField, String valueDescription, String errorTitle, boolean positiveValue, boolean showMessage, boolean valid)
  8. verifyNumber_geq(JTextField field, Long number)
  9. within(javax.swing.JTextField input, double low, double high, Vector errMsgList, String errMsg)