Java 8 NumberFormatter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 NumberFormatter class.

This code example shows how to use the following methods:setAllowsInvalid, setValueClass, setMaximum, setMinimum
This code example shows how to use the following methods:setAllowsInvalid, setCommitsOnValidEdit, setValueClass, setMinimum
    // 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;
        }; 
    } 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setAllowsInvalid
    } 
     
    private static NumberFormatter getNumberFormatter() {
         
        DecimalFormat format = new DecimalFormat( "#####" );
        NumberFormatter f = new NumberFormatter( format );
         
        f.setAllowsInvalid( false );
         
        return f;
         
    } 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMaximum, setMinimum
This code example shows how to use the following methods:setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass, setMaximum
This code example shows how to use the following methods:setValueClass, setMinimum
        } 
    } 
 
    private JFormattedTextField getUnitJFormattedTextField() {
        NumberFormat format= new DecimalFormat("#,##0.###");
        NumberFormatter formatter= new NumberFormatter(format);
        formatter.setMinimum(1.0);
        formatter.setValueClass(Double.class);
        JFormattedTextField field = new JFormattedTextField(formatter);
        return field;
    } 
 
    /** 
     * Returns the ratio of splitting. If this is a reverse split (aka merging), 
     * ratio will be less than 1, but greater than 0. Returns null if user 
     * doesn't press OK button. 
     * 
     * @return the ratio of splitting 
     */ 
    public Double getRatio() {
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setCommitsOnValidEdit, setMaximum, setMinimum
	 
	public <T extends Number & Comparable<T>> NumberField(T min, T max, T value, NumberFormatter f)
		{ 
		super(f);
		formatter = f;
		f.setMinimum(min);
		f.setMaximum(max);
		if (value != null)
			setValue(value.compareTo(min) < 0 ? min : value.compareTo(max) > 0 ? max : value);
		} 
 
	public <T extends Number & Comparable<T>>void setRange(T min, T max)
		{ 
		formatter.setMinimum(min);
		formatter.setMaximum(max);
		commitOrRevert(); 
		} 
 
	public Integer getIntValue()
		{ 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setOverwriteMode, setValueClass
    DecimalFormat decimalFormat = newDecimalFormat(pattern, decimalPlaces);
 
    NumberFormatter numberFormatter = newNumberFormatter(decimalFormat, maxLength);
 
    // Ensure we keep insert mode 
    numberFormatter.setOverwriteMode(false);
 
    return numberFormatter;
 
  } 
 
  /** 
   * @param pattern       The pattern to use 
   * @param decimalPlaces The number of decimal places to allow 
   * 
   * @return A decimal format based on the current configuration 
   */ 
  private static DecimalFormat newDecimalFormat(String pattern, int decimalPlaces) {
 
    // Adjust edit/display formats to the current configuration 

4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setFormat
     */ 
    public void setFormat( ScientificFormat format )
    { 
        DefaultEditor e = (DefaultEditor) getEditor();
        NumberFormatter f = (NumberFormatter)e.getTextField().getFormatter();
        f.setFormat( format );
    } 
} 
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
        integer = new JFormattedTextField();
        add(relation, BorderLayout.WEST);
        add(integer, BorderLayout.CENTER);
        NumberFormat format = NumberFormat.getIntegerInstance();
        format.setGroupingUsed(false);
        NumberFormatter formatter = new NumberFormatter(format);
        DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
        integer.setFormatterFactory(factory);
        integer.setHorizontalAlignment(JFormattedTextField.RIGHT);
        setParameter(new IntegerRelation()); 
    } 
 
    public void setParameter(@Nullable Object parameter) { 
        IntegerRelation rel;
        if (parameter != null) { 
            rel = (IntegerRelation) parameter;
        } else { 
            rel = new IntegerRelation();
        } 
        integer.setValue(rel.getInteger());
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 NumberFormatter Methods: