bonsoir
j'ai problème avec le champ JFormattedTextField par exemple si je clic sur le bouton sans saisir un chiffre alors le teste22.length() me retourne 0
mais si je tape un chiffre alors teste22.length() me retourne teste = 20

toujours numéro 20 et pas la langueur de champ je n'arrive pas à comprendre le problème



Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
 String teste22 = jtf2.getText();
System.out.println("test  " +teste22.length());
	 if (jtf2.getText().length()< 6 )
						  {
 
JOptionPane ddd1 = new JOptionPane();ddd1.showMessageDialog(test.this, " 99","e",JOptionPane.INFORMATION_MESSAGE);	               	 
 
}
}
}
 
 
 
private JFormattedTextField  getJTextField3() {
	if (jtf2 == null) {
		MaskFormatter mask = new MaskFormatter();
		jtf2 = new JFormattedTextField(mask);
		jtf2.setBounds(new Rectangle(169, 38, 146, 37));
		jtf2.setText("");
 
 
		    try {
 
		    	mask.setMask("####################");
		        mask.setValidCharacters("1234567890");
		    } catch (Exception e) {
		        e.printStackTrace();
		    }
		    mask.setAllowsInvalid(false);
 
		    jtf2.setFocusLostBehavior(JFormattedTextField.PERSIST);
	}
	return jtf2;
}
 
merci d'avance