Mascara Valor monetário no JFormattedTextField

2 respostas
B

Prezados,

Gostaria de saber como faço para colocar a mascara valor monetário no JFormattedTextField.
Eu faço assim: MaskFormatter mask = new MaskFormatter ("###.###.###,##"); Assim não rola, pois sai errado. Agradeço desde já as dicas e sugestões.

2 Respostas

A

Deu uma olhada nesse site.

http://www.exampledepot.com/egs/javax.swing.text/pkg.html

andredeividi

Num sei se te ajuda mas eu uso algo assim

public static String FormataNumeros(String valor, int nDecimais) {
        String result = new String("");
        if (valor == null)
            result = "0";
        else
            result = SomenteNumeros(valor);
        String casasDecimais = new String("");
        
        if (result.length() &lt= nDecimais)
            while( result.length() &lt= nDecimais) result = "0" + result;
        result = result.substring(0, result.length() - nDecimais) + "." + result.substring(result.length() - nDecimais);
        
        for (int i = 0; i &lt nDecimais; i++)
            casasDecimais = casasDecimais + "0";
        
        DecimalFormat a;
        if (nDecimais &gt 0)
            a = new DecimalFormat("###,###,##0." + casasDecimais);
        else
            a = new DecimalFormat("###,###,##0");
        
        result = a.format(Double.parseDouble(result));
        
        return result;
    }
Criado 23 de novembro de 2006
Ultima resposta 15 de dez. de 2006
Respostas 2
Participantes 3