Getting exception when trying to get paragraph bounds when caret moves
See original GitHub issueThis is a strange one, please bear with me!
I have a custom paragraph graphic that makes use of area.getCharacterBoundsOnScreen and area.getParagraphBoundsOnScreen to determine where nodes within the graphic should be placed.
This code works well enough but if I have a node on the same line as the caret and I press return and the caret would leave the visible area then I get the following exception:
java.lang.IllegalArgumentException: This ParagraphText is not the parent of the given shape (CaretNode(name=main-caret position=324 paragraphIndex=1 columnPosition=0 Path[elements=[MoveTo[x=0.0, y=0.0], LineTo[x=0.0, y=37.0]], fill=null, fillRule=NON_ZERO, stroke=0x000000ff, strokeWidth=1.0])):
Expected: ParagraphText@663439511(paragraph=null)
Actual: null
at org.fxmisc.richtext.ParagraphText.checkWithinParagraph(ParagraphText.java:312)
at org.fxmisc.richtext.ParagraphText.getCaretBounds(ParagraphText.java:251)
at org.fxmisc.richtext.ParagraphBox.getCaretBounds(ParagraphBox.java:204)
at org.fxmisc.richtext.GenericStyledArea.followCaret(GenericStyledArea.java:1698)
at org.fxmisc.richtext.GenericStyledArea.lambda$layoutChildren$46(GenericStyledArea.java:1458)
at org.reactfx.Suspendable.suspendWhile(Suspendable.java:49)
at org.fxmisc.richtext.GenericStyledArea.layoutChildren(GenericStyledArea.java:1450)
at javafx.graphics/javafx.scene.Parent.layout(Parent.java:1206)
The image below should give a rough idea of what’s going on.
Once I press return and thus the caret would move below the bottom of the scrollpane viewport I get the exception above. This doesn’t happen if I type normally and the line wraps at the edge of the area. Nor does it happen if there is space in the scrollpane viewport to go to the next line. It only happens when I press return and the caret is at the bottom of the viewport.
I can add my position lookup code if you like, it’s a bit of a mess at the moment but it essentially just makes use of a combination of getCharacterBoundsOnScreen and getParagraphBoundsOnScreen depending upon where the position is in relation to the text.
I suspect the exception is being caused by the getXXX calls triggering a layout but I don’t know how to prevent it happening because the calls are already being made in a layoutChildren call. It’s notable here that this exception isn’t being thrown from my code and none of my code is calling requestFollowCaret.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top GitHub Comments
Yes I’m not great with gradle either, that’s the trouble with build tools you don’t use them enough to be get good at them.
Anyway, I modified file:
richtextfx/build.gradle
in the compileJava task I’ve added:
I’m not sure if all of those exports are needed for RichTextFX (I assume they are because I added them 😃. The [path to modules] is just the location of where the javafx sdk library modules are, in my case this is: D:/reference/java/javafx/javafx-sdk-12/lib. I’m sure there is a gradle options file where the path could be defined but I don’t have time to find out how to do that.
I’ve also modified the compileJava9Java task as well with the same compileArgs, but I’m not sure if that’s needed for javafx 12+. The changes will only work for ./gradlew jar. Using ./gradlew fatJar will cause it to break so some other tasks probably need changing as well but again I just don’t have time and only need the normal jar files.
@Siedlerchr thanks for that, it’s good to know.