Formatação errada ao preencher campo

1 resposta
pix

Seguinte, estou fazendo a mascara de um JTextField() desta forma:

public class CompoFloat extends PlainDocument {

        private int NUMERO_DIGITOS_MAXIMO = 14;

        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            String texto = getText(0, getLength());

            for (int i = 0; i < str.length(); i++) {
                char c = str.charAt(i);
                if (!Character.isDigit(c)) {
                    return;
                }
            }
            if (texto.length() < this.NUMERO_DIGITOS_MAXIMO) {
                super.remove(0, getLength());
                texto = texto.replace(".", "").replace(",", "");
                StringBuffer s = new StringBuffer(texto + str);

                if (s.length() > 0 && s.charAt(0) == '0') {
                    s.deleteCharAt(0);
                }

                if (s.length() < 3) {
                    if (s.length() < 1) {
                        s.insert(0, "000");
                    } else if (s.length() < 2) {
                        s.insert(0, "00");
                    } else {
                        s.insert(0, "0");
                    }
                }

                s.insert(s.length() - 2, ",");

                if (s.length() > 6) {
                    s.insert(s.length() - 6, ".");
                }

                if (s.length() > 10) {
                    s.insert(s.length() - 10, ".");
                }

                super.insertString(0, s.toString(), a);
            }
        }

        public void remove(int offset, int length) throws BadLocationException {
            super.remove(offset, length);
            String texto = getText(0, getLength());
            texto = texto.replace(",", "");
            texto = texto.replace(".", "");
            super.remove(0, getLength());
            insertString(0, texto, null);
        }


}

E no campo

txtQuantEntra.setDocument(new erpnota.funcao.CompoFloat());

O problema é que quando busca algum dado no banco de dados, exemplo "10.00" que transformo em "1000" pra ele preencher o campo ele fica "0.010,00"
Alguém pode me ajudar?

1 Resposta

pix

ninguem?

Criado 25 de setembro de 2009
Ultima resposta 28 de set. de 2009
Respostas 1
Participantes 1