JFormDesigner / FlatLaf

FlatLaf - Swing Look and Feel (with Darcula/IntelliJ themes support)
https://www.formdev.com/flatlaf/
Apache License 2.0
3.42k stars 272 forks source link

Getting javax.swing.text.StateInvariantError: GlyphView: from paintsafely method of flattextpaneUI #868

Closed VKaddala closed 4 months ago

VKaddala commented 4 months ago

Hi, I have implemented a UI where there is a styledtextpane . I try to copy the text with a new line character and paste it inside the field and it gets pasted twice. When I try to delete each character using the backspace, it gives the following error:

`javax.swing.text.StateInvariantError: GlyphView: Stale view: javax.swing.text.BadLocationException: Invalid location

            at java.desktop/javax.swing.text.GlyphView.getText(GlyphView.java:138)

            at java.desktop/javax.swing.text.GlyphPainter1.paint(GlyphPainter1.java:118)

            at java.desktop/javax.swing.text.GlyphView.paintTextUsingColor(GlyphView.java:484)

            at java.desktop/javax.swing.text.GlyphView.paint(GlyphView.java:475)

            at ui.StyledTextPane$StyledTextGlyphView.paint(StyledTextPane.java:1342)

            at java.desktop/javax.swing.text.BoxView.paintChild(BoxView.java:162)

            at java.desktop/javax.swing.text.BoxView.paint(BoxView.java:434)

            at java.desktop/javax.swing.text.BoxView.paintChild(BoxView.java:162)

            at java.desktop/javax.swing.text.BoxView.paint(BoxView.java:434)

            at java.desktop/javax.swing.text.ParagraphView.paint(ParagraphView.java:573)

            at java.desktop/javax.swing.text.BoxView.paintChild(BoxView.java:162)

            at java.desktop/javax.swing.text.BoxView.paint(BoxView.java:434)

            at java.desktop/javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1538)

            at java.desktop/javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:757)

            at com.formdev.flatlaf.ui.FlatTextPaneUI.paintSafely(FlatTextPaneUI.java:215)

            at java.desktop/javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:915)

            at java.desktop/javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:894)`

Steps I tried to reproduce the issue: Trying to copy the description from notepad++ and pasting it in field and later trying to edit the text (i.e. Deleting the text using backspace) error is encountered.

Actual image of text, when the paste happened.

image

This only happens when there is new line character.

Please help me in understanding the issue. @DevCharly

DevCharly commented 4 months ago

FlatTextPaneUI.paintSafely() simply invokes super.paintSafely().

https://github.com/JFormDesigner/FlatLaf/blob/d510fee7f6b3c05c323ed4560d7dde2190cefa02/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTextPaneUI.java#L214-L216

I can't see any relation to FlatLaf. Also have no idea what could cause that exception...