private void KeyAction(java.awt.event.KeyEvent evt) {
if (evt.getKeyCode() == 91) {
int pos = txt.getCaretPosition();
txt.insert("}",pos);
}
}
The function is currently showing But why it’s showing }{, but I’m expecting the output to be {}. How can I fix this?
How about:
Pos is the position of the current character. Inserting at pos puts the inserted item in front of the current character. For your code, the output you see is the expected result. Try inserting after the current character.