0
I’d like to know why the class DefaultStyledDocument
error when inserting a line break, either by \n
or by System.lineSeparator()
.
Minimal example:
StyleContext sc = new StyleContext();
final DefaultStyledDocument doc = new DefaultStyledDocument(sc);
final Style redStyle = sc.addStyle("RED", null);
redStyle.addAttribute(StyleConstants.Foreground, Color.RED);
jTextPane1.setDocument(doc); //esse jtext ja esa inserido no frame
doc.insertString(jTextPane1.getText().length(), "[pode ir qualquer string aqui]"+System.lineSeparator(), redStyle); //tentando pular linha com lineSeparator()
Error:
GRAVE: null
javax.swing.text.BadLocationException: Invalid insert
at javax.swing.text.GapContent.insertString(GapContent.java:129)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:723)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)