I do not think this is a new problem. But it seems that an error occurs whenever the ordered / unordered list in JTextPane (EditorKit β HTMLEditorKit, Document β HTMLDocument) is deleted from the very beginning using the backspace key. The following is an exception caused by the getText () method of GlyphView.
Exception in thread "AWT-EventQueue-0" javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location
I can provide SSCCE for this. But imitating is not very difficult. Just use the JTextPane with the HTMLEditorKit model and the HTMLDOcument installed inside it. Either use the custom action "InsertOrderedList", or you can insert a row
<HTML><HEAD></HEAD><BODY><UL><LI></LI></UL></BODY></HTML>
which will lead to the insertion of an ordered / unordered list inside the text panel.
The strange parts of this error are as follows:
As soon as you start deleting characters (and if you have lines below the bulleted list), the characters will be deleted until you click the last character of the last marker item. Once you achieve this, the carriage simply refuses to move up, and an error from GlyphView appears.
Sometimes it happens that after you have deleted most of the characters, you still can not delete the first mark of the list. It just freezes until you do ctrl + a and then backspace.
I saw these errors in almost all Java-based HTML editors available on the Internet, except for JWebEngine, where this behavior is not. Unfortunately, JWebEngine is not open, and therefore, I cannot look inside their code to understand how they solved this problem.
I assume that the notification that came from the model of the HTML document has some problems due to which the cursor positioning code does not work correctly. I also searched Sun's error database to see if this particular problem was raised, but could not be found (although I saw quite a few errors that are very similar to this). I'm also very sure that someone must have noticed this before and must have gotten his attention from the Swing team.
Does anyone who works with the Swing part (especially the text) know if this problem was raised using Sun or is there any known solution that was found to mitigate the problem?
Although it is possible that the user can still remove lists from the panel with the mouse, not being able to do the same with the backspace key, it just seems very strange.
SSCCE is now bound. To reproduce the error pls. follow the steps as shown in the attached figure.
- Add a line of text. Then add 2/3 of the bullet element by clicking the button above the text panel. Now place the carriage at the end of the last char of the last bullet and continue to press all the backspace until all characters are deleted.
Observed behavior: the last bullet will hang (not removed) and the exception will be thrown (as indicated above)
Expected: There should be no exceptions, and the contents of the text panel should be cleared.
public class Test { static final JFrame frame = new JFrame (); static final JTextPane textPane = new JTextPane (); static EditorKit kit; static JButton listButton; public static void createAndShowGUI () {
