Good evening,
I have the following problem. I do not know how to validate if the field of the JFormatted TextField has something written or not, so long as the formatting ###. ###. ### - ## is not considered valid or is required is actually filled by numbers .
JFormattedTextField
// CPF
JLabel lblCpf = new JLabel("CPF");
contentPane.add(lblCpf, "cell 0 0");
JFormattedTextField ftCpf = new JFormattedTextField();
MaskFormatter mfCPF = new MaskFormatter();
try {
mfCPF.setMask("###.###.###-##");
mfCPF.install(ftCpf);
ftCpf.setText("");
} catch (ParseException e1) {
e1.printStackTrace();
}
contentPane.add(ftCpf, "cell 0 1,growx");
Ok Button
// Botão > Ok
JButton btnOk = new JButton("Ok");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// Validar Campos
if(ftCpf.equals("###.###.###-##") && tfPergunta.getText().equals("") && tfResposta.getText().equals(""))
JOptionPane.showMessageDialog(null, "Por favor, preenchao todos os campos acima", "Informação", JOptionPane.INFORMATION_MESSAGE);
else if(tfPergunta.getText().equals(""))
JOptionPane.showMessageDialog(null, "Por favor, preenchao campo de Pergunta.", "Informação", JOptionPane.INFORMATION_MESSAGE);
else if(tfResposta.getText().equals(""))
JOptionPane.showMessageDialog(null, "Por favor, preenchao campo da Resposta.", "Informação", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, "Campos preenchidos.", "Informação", JOptionPane.INFORMATION_MESSAGE);
// Capturar Dados
String cpf = mfCPF.getMask();
String pergunta = tfPergunta.getText();
String resposta = tfResposta.getText();
}
});
panel.add(btnOk, "cell 0 0,grow");