question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting exception when trying to get paragraph bounds when caret moves

See original GitHub issue

This 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.

caret-exception

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:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
garybentleycommented, Aug 18, 2020

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:

options.compilerArgs =
[
   '--add-exports',
   'javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
   '--add-exports',
   'javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
   '--add-exports',
   'javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED',
   '--add-exports',
   'javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED',
   '--add-exports',
   'javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED',
       '--add-modules=java.base,javafx.controls,javafx.swing,javafx.media,javafx.web,java.instrument,jdk.attach',
       '--module-path',
       '[path to modules]'
   ]

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.

0reactions
garybentleycommented, Oct 5, 2020

@Siedlerchr thanks for that, it’s good to know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Need to move caret to end of a textbox when its bound ...
When this happens, the textbox is properly updated but the caret moves to the front of the text. We have a method in...
Read more >
Selection and Range - The Modern JavaScript Tutorial
JavaScript can access an existing selection, select/deselect DOM nodes as a whole or partially, remove the selected content from the document, ...
Read more >
How to Use Text Areas (The Java™ Tutorials > Creating a GUI ...
If the displayed text has a limited length and is never edited by the user, use a label.
Read more >
Create type in Photoshop - Adobe Support
In Adobe Photoshop, learn how to create type. Find out how to enter point and paragraph type, use placeholder text, and more.
Read more >
Paint | Android Developers
Convenience method for callers that want to have FontMetrics values as integers. ... Create a new paint, initialized with the attributes in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found