Dear Christoph:

Thanks for a detailed request!

You are right, there is no easy way to achieve what you want right now.  Unlike 
TextArea, RichTextArea/CodeArea are virtualized, so things are a bit more 
difficult, especially when the target text position is outside of the rendered 
area.

As for the public API in the context of JDK-8380073, there are two choices:

  1.
position the current caret at the desired viewport location
  2.
position an arbitrary TextPos

For positioning, it could use either the viewport (x,y) coordinates or the 
percentage of the viewport width/height as you suggested.  In addition to that, 
there might be a need to control the horizontal scrolling separately if the 
wrapText property is off.

Thanks again for using the CodeArea in your project.  If you have more 
feedback, do not hesitate.

-andy



From: Siedlerkiller <[email protected]>
Date: Friday, November 13, 2026 at 13:58
To: [email protected] <[email protected]>
Subject: [External] : RichTextArea: public API to scroll a text position into 
view / center it (JDK-8380073)

Hi,

JabRef [0] uses the incubator CodeArea for its BibTeX source editor.

We would like to support the macOS text-editing shortcut Ctrl+L, which
scrolls the view so that the caret line is vertically centered without
moving the caret [1].

This is the use case of JDK-8380073 [2]: positioning a given text position
at a defined place in the viewport.

For TextArea, this works with public API:

   -

   TextAreaSkin#getCaretBounds() [3]
   -

   TextArea#setScrollTop(double) [4]

For RichTextArea [5] (checked in 27 and 28-ea+12), the public API offers no
caret or character bounds, no scroll position, and no "scroll into view"
function.

Only getTextPosition(x, y), getDocumentArea(), and pageUp()/pageDown() are
available.

The functionality exists internally in the non-exported VFlow (source at
commit c641387 [6]):

   -

   VFlow#getCaretInfo() [7]
   -

   VFlow#scrollVerticalFraction(double) [8]
   -

   VFlow#scrollToVisible(double, double) [9]
   -

   VFlow#scrollCaretToVisible() [10]

Public methods in RichTextArea [11] would cover this use case. For example:

   -

   Bounds getCaretBounds() (or bounds for an arbitrary TextPos), in local
   coordinates, like TextAreaSkin#getCaretBounds().
   -

   A way to scroll so that a TextPos is shown at a given relative vertical
   position, e.g. scrollToPosition(TextPos pos, double fraction), with 0.0
   = top, 0.5 = center, 1.0 = bottom.

The 0.0 case covers JDK-8380073, while 0.5 covers caret centering.

Thanks for the RichtText control so far; the control works great!

Best regards,
Christoph
------------------------------

References:

[0] https://github.com/JabRef/jabref

[1] https://github.com/JabRef/jabref/issues/17771

[2] https://bugs.openjdk.org/browse/JDK-8380073

[3]
https://openjfx.io/javadoc/25/javafx.controls/javafx/scene/control/skin/TextAreaSkin.html#getCaretBounds()

[4]
https://openjfx.io/javadoc/25/javafx.controls/javafx/scene/control/TextArea.html#setScrollTop(double)

[5]
https://openjfx.io/javadoc/25/jfx.incubator.richtext/jfx/incubator/scene/control/richtext/RichTextArea.html

[6]
https://github.com/openjdk/jfx/tree/c6413874cc60c9ccbcd8914ba18154a96bbf7536

[7]
https://github.com/openjdk/jfx/blob/c6413874cc60c9ccbcd8914ba18154a96bbf7536/modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/VFlow.java#L566

[8]
https://github.com/openjdk/jfx/blob/c6413874cc60c9ccbcd8914ba18154a96bbf7536/modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/VFlow.java#L951

[9]
https://github.com/openjdk/jfx/blob/c6413874cc60c9ccbcd8914ba18154a96bbf7536/modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/VFlow.java#L993

[10]
https://github.com/openjdk/jfx/blob/c6413874cc60c9ccbcd8914ba18154a96bbf7536/modules/jfx.incubator.richtext/src/main/java/com/sun/jfx/incubator/scene/control/richtext/VFlow.java#L1005

[11]
https://github.com/openjdk/jfx/blob/c6413874cc60c9ccbcd8914ba18154a96bbf7536/modules/jfx.incubator.richtext/src/main/java/jfx/incubator/scene/control/richtext/RichTextArea.java

Reply via email to