JDK-8119007 : Text.getImpl_caretShape() returns wrong shape when Text is not the first child of TextFlow
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Incomplete
  • Submitted: 2013-08-16
  • Updated: 2020-11-04
  • Resolved: 2013-08-20
Related Reports
Relates :  
Description
The problem is that Text.getImpl_caretShape() obtains TextLayout from the parent TextFlow and then calls TextLayout.getCaretShape(pos, ...) with pos being its internal caret position. The result is getting the caret shape for position pos in the TextFlow, not relative to Text.

The problematic code in Text.java:

    int pos = getImpl_caretPosition();
    ...
        TextLayout layout = getTextLayout(); // returns parent's TextLayout
        return layout.getCaretShape(pos, bias, x, y);

I would welcome any solution, e.g. either of
1) Text.getImpl_caretShape() returns correct caret shape relative to Text;
2) Text.getImpl_caretShape() return correct caret shape relative to parent TextLayout;
3) Introduce TextFlow.getImpl_caretShape().

Thanks,
Tomas
Comments
It worked nicely, thanks.
11-11-2013

Hi Tomas, it is obviously a hack but for JavaFX8 I don't see a better way out. I hope to provide better support in our next version. sorry.
08-11-2013

That's a lot less dirty than what we add to override in Swing at the time. Good energy here !
08-11-2013

Oh, thanks! :) So the trick is to use reflection to invoke a private method on Text to obtain the underlying TextLayout and then work directly with TextLayout. Dirty, but should work.
08-11-2013

It's above, on this page, as an attached file. It took me some time also :)
08-11-2013

Hi Felipe, could you please point me to the above-mentioned TextFlowBg.java, I cannot find it. Thank you.
08-11-2013

Ok, sorry. I see it's already fixed "internally". Nice. I also relayed your previous response to the CodeAreaFX developer.
07-11-2013

Hi Olivier, I think that is a different problem. See RT-34072
07-11-2013

I hope I'm not on another subject, but using JDK8 b114, this code shows that the tab between '1' and '2' in the TextArea is a problem: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextArea; import javafx.stage.Stage; public class TestTabInTextArea extends Application { @Override public void start(Stage primaryStage) { Scene scene = new Scene(new TextArea("1 2"), 1000, 500); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
07-11-2013

getImpl_caretPosition() is an internal API, and it is not meant to work with TextFlow. What you want is RT-29077. That said, see TextFlowBg.java, I suspect the same workaround could be used to get the caretPosition.
07-11-2013

I use the project CodeAreaFX. It's a very nice use of TextFlow, but this bug makes their control unusable. They may not use an "all-public" API, but I think you've added the TextFlow for open source controls like this one to exist.
07-11-2013

I am going to mark this as "incomplete" pending a reproducible test case that uses public API. Note that none of the *impl_* methods are part of the public API (even though they may have public visibility in the Java class).
20-08-2013

The same goes for Text.getImpl_selectionShape().
17-08-2013