souci de modification du rendu d'un JTexfield
Bonsoir à tous,voici mon problème :
Dans mon interface j'ai plusieurs JTexfield qui doivent contenir chacun des entiers de 5 caractères maximum,je voudrais pouvoir à la fin de la saisie ajouter des zero a gauche,j'ai tenter de le faire mais je ne suis pas satisfait du rendu,je penses qu'avec mon code la valeur du champ au lieu d'etre un int sera un String.
quelqu'un pourrait-il m'aider.Merci. Code :
Code:
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
| private void TxtNumRegistreKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
String val1="0000";String val2="000";String val3="00";String val4="0";
int Contval1=Integer.parseInt(val1);
int Contval2=Integer.parseInt(val2);
int Contval3=Integer.parseInt(val3);
int Contval4=Integer.parseInt(val4);
int Varval1,Varval2,Varval3,Varval4;
int valeur=getTxtNumRegistre();
if(getTxtNumRegistre()<10)
// Varval1= Contval1 + Integer.parseInt(TxtNumRegistre.getText());
// setTxtNumRegistre(Varval1);
TxtNumRegistre.setText("000"+getTxtNumRegistre());
else if(getTxtNumRegistre()<100)
//Varval2= Contval2 + Integer.parseInt(TxtNumRegistre.getText());
TxtNumRegistre.setText("000"+getTxtNumRegistre());
else if(getTxtNumRegistre()<1000)
//Varval3= Contval3 + Integer.parseInt(TxtNumRegistre.getText());
TxtNumRegistre.setText("00"+getTxtNumRegistre());
else if(getTxtNumRegistre()<10000)
TxtNumRegistre.setText("0"+getTxtNumRegistre());
// Varval4= Contval4 + Integer.parseInt(TxtNumRegistre.getText());
} |
et voici le code du getter : getTxtNumRegistre()
Code:
1 2 3 4
| public int getTxtNumRegistre() {
int valTxtNumRegistre=Integer.parseInt(TxtNumRegistre.getText()) ;
return valTxtNumRegistre;
} |