I’m writing a vt100 emulator and I’m using a JTextPane with a DefaultStyledDocument to display the formatted text. Now I want to implement the backspace, so i need to be able to remove the last character.
I tried the following:
doc.remove(doc.getEndPosition().getOffset()-1, doc.getEndPosition().getOffset());
But I keep getting a ‘javax.swing.text.BadLocationException: Invalid remove’
How should this be done?
You’re using the API wrong. The last parameter is the number of characters to remove which in your case should be 1.
Here is the API for
Document.remove(int, int).