So I have a JTextPane and I added a keyListener, like that I can know if the enter button was pressed :
JTextPane textPane = new JTextPane();
textPane.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_ENTER){
// add there the code to add a character to the textPane!
}
}
@Override
public void keyReleased(KeyEvent e) {
}
});
But now I am bloked, how to add a character '}' to the textPane?
(not anywhere, just after the cursor's position, to the following...)