0

I currently have a TextFlow, putting Text Nodes and other types of nodes into it, I'm trying to make the text selectable using mouse and key events, but the methods setSelectionStart and setSelectionEnd don't seem to behave the way they should, like it works fine for the first Text node but not for others

Here is a minimal reproducible example :

@Override
public void start(Stage ps) {
    TextFlow flow = new TextFlow();
    flow.setPadding(new Insets(10));
    
    Text t1 = new TextNode("first ");
    Text t2 = new TextNode("second ");
    Text t3 = new TextNode("third");
    
    t1.setSelectionStart(2);
    t1.setSelectionEnd(6);
    t2.setSelectionStart(0);
    t2.setSelectionEnd(4);
    
    flow.getChildren().addAll(t1, t2, t3);
    
    ps.setScene(new Scene(flow,400,300));
    ps.show();
}

private class TextNode extends Text {
    public TextNode(String s) {
        super(s);
        setFont(Font.font(18));
        setSelectionFill(Color.RED);
    }
}

I'm basically creating a TextFlow and inserting 3 Text nodes into it, i want to be able to make a selection across the first and second Text nodes, but it's not working, see the screenshot below

screenshot

The docs indicate that

When a Text node is inside of a TextFlow, some of its properties are ignored

But I don't seem to find the correct approach to make a continuous selection across Text nodes, note that i can't join them in a single Text node because there could be a non-text node between them, any help would be appreciated.

SDIDSA
  • 894
  • 10
  • 19
  • not supported - see the duplicate for options (and a reference to an open issue) – kleopatra Aug 01 '21 at 09:57
  • the answer on that question says that Text is not selectable, but the Text node has functions to set the selection start and end, and it works for a single Text node (changes the color of the selected range to the selectionFill property), it seems like the Textflow is overriding some of that behaviour in a way that is not documented anywhere and that i don't understand. – SDIDSA Aug 01 '21 at 15:37
  • 1
    what don't you understand? it's simply not supported - you have to do it yourself (don't know how simple/complex that would be). Do a bit of research, read the sources, maybe somebody has implemented something useful. – kleopatra Aug 01 '21 at 16:32
  • totally understandable, thank you for your help – SDIDSA Aug 01 '21 at 22:41

0 Answers0