I want a JTextFeild event when keyboard button pressed.I want concatenate "ADZ" text to the front whole text.(If we enter "2" whole text should be "ADZ2") THe Action will performed only first key press.After any key pressing action won't be performed.Action will performed only once. I tried below code,but if type 22 it gives"ADZADZ22".
private void JTextFeild1KeyTyped(java.awt.event.KeyEvent evt) {
String num1 = JTextFeild1.getText();
JTextFeild1.setText("ADZ"+num1);
I want this if type 22, it will gives ADZ22.
A simple way to solve it, is to check if the prefix is already there. This avoids that the same prefix is added twice.
Please note: Java coding rules would suggest to make field names (e.g.
jTextField
) start with a lower case character. The same goes for method names (e.g.private void jTextField1KeyTyped
)