I 'm working on code that takes a string from a JTextField
and puts it on a JLabel
.
But my problem is always the string shown is missing the last character.
private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {
String ch=jTextField1.getText();
jLabel1.setText(ch);
}
It's better to use a DocumentListener to check for changes in the jTextField. Not only will that notify you after the changes of the additional character are incorporated, but you will also be notified about changes unrelated to keyboard events (e.g. pasting text).