Validation JTextField

0

I'm trying to validate the txtServicoValor field that receives a type BigDecimal , follow my code, the validation is barring both the correct digits and the incorrect form, thank you for the help.

MaskFormatter mask = new MaskFormatter("###.###,#00.00");

JFormattedTextField campoTexto = new JFormattedTextField(mask);

mask.setValidCharacters("0123456789");

validos.install(campoTexto);

if(txtServico.getText().length() > 0
        && txtServicoValor.getText().length() > 0
        && (txtServicoValor.getText().replaceAll("\.", "").replace(",",".")).equals(campoTexto))
{
    servico.setServico(txtServico.getText());
    servico.setValorServico(new BigDecimal(txtServicoValor.getText().replaceAll("\.", "").replace(",",".")));
}
    
asked by anonymous 01.12.2014 / 21:07

1 answer

1

Your problem is a very silly mistake. He is here:

(txtServicoValor.getText().replaceAll("\.", "").replace(",",".")).equals(campoTexto)

This is a String :

(txtServicoValor.getText().replaceAll("\.", "").replace(",","."))

This is JFormattedTextField :

campoTexto

A String will never equal a JFormattedTextField .

    
01.12.2014 / 22:04