I have one extends jFormattedTextField and in this field, I have a method to verify if it is empty, but in jTextField it works, but in jFormattedTextField no.
As I pass the fields on my frame:
RVDFormattedTextField[] obrigatoriosFTF = new RVDFormattedTextField[1];
private void setaObrigatorios() {
obrigatoriosFTF[0] = rvfCNPJ;
}
if (RVDFormattedTextField.isEmpty(obrigatoriosFTF)) {
Mensagem.aviso("Preencha os campos obrigatórios (*).", this);
} else {
Method in jFormattedTextField:
public static boolean isEmpty(RVDFormattedTextField[] campos) {
Boolean ok = false;
for (int i = 0; i < campos.length; i++) {
if (Formatacao.removerFormatacao(campos[i].getText()).trim().isEmpty()) {
ok = true;
if (campos[i].isEditable()) {
campos[i].setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 51, 51)));
}
} else {
campos[i].setBorder(javax.swing.BorderFactory.createEtchedBorder());
}
}
return ok;
}
Does not show errors, tried to put a sout in the method and debug however nothing happens.
Method removerFormatacao
public static String removerFormatacao(String dado) {
String retorno = "";
for (int i = 0; i < dado.length(); i++) {
if (dado.charAt(i) != '.' && dado.charAt(i) != '/' && dado.charAt(i) != '-' && dado.charAt(i) != '(' && dado.charAt(i) != ')') {
retorno = retorno + dado.charAt(i);
}
}
return (retorno);
}
Method formatarCNPJ (mask)
public static void formatarCnpj(JFormattedTextField campo) {
try {
MaskFormatter m = new MaskFormatter();
m.setPlaceholderCharacter(' ');
m.setMask("##.###.###/####-##");
campo.setCaretPosition(0);
campo.setFormatterFactory(null);
campo.setFormatterFactory(new DefaultFormatterFactory(m));
campo.setValue(null);
} catch (Exception e) {
System.err.println(e);
}
}
I tried to remove these two methods, but it still didn't work.
Well, which mask is used on the JFormattedText and how is the Formatacao.removerFormatacao
implementation?