0

I'm using RichTextFX and I was surprised that the CodeArea does not come with a scrollbar enabled by default. How can I get this to appear?

Steve
  • 4,457
  • 12
  • 48
  • 89
  • 1
    The [demo code](https://github.com/TomasMikula/RichTextFX/blob/master/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/JavaKeywords.java) wraps the `CodeArea` in a `VirtualizedScrollPane` (from [Flowless](https://github.com/TomasMikula/Flowless)). I haven't tried it, but you could probably wrap it in a plain old `ScrollPane` too, though that would likely not be as efficient. – James_D Jul 20 '17 at 01:54
  • The VirtualizedScrollPane doesn't seem to support FXML (seems like a pretty big oversight) so I'm trying to use ScrollPane. I can still scroll with the mouse wheel, but when I setHbarpolicy="ALWAYS" I get a scrollbar that's full size (as in, I can't move it). Any ideas? – Steve Jul 20 '17 at 14:28
  • What do you mean by "doesn't seem to support FXML"? `` should work. – James_D Jul 20 '17 at 14:29
  • It looks like a current issue, https://github.com/TomasMikula/Flowless/issues/25 – Steve Jul 20 '17 at 14:37
  • and when I try that I get No Such Method exceptions – Steve Jul 20 '17 at 14:38
  • That's weird: the [constructors](https://github.com/TomasMikula/Flowless/blob/master/src/main/java/org/fxmisc/flowless/VirtualizedScrollPane.java) clearly have `@NamedArg` annotations on the parameters. Maybe the dependency for flowless is not in sync with the latest version? – James_D Jul 20 '17 at 14:49
  • What version are you using? I just downloaded 6, same error. At this point maybe I should post a new question – Steve Jul 20 '17 at 16:03
  • Oh, to clarify: my original suggested FXML was based off looking at the source code on github. I subsequently tested with the 1.0.0-SNAPSHOT version of RichTextFX, which gave me the same result you get, but it really shouldn't. (Because the FXML loader should not need a zero-argument constructor.) So... not sure how to proceed; maybe try building Flowless from source (or test something first and see if the same constellation of constructors with `@NamedArg`-annotations really does work in FXML...)? – James_D Jul 20 '17 at 16:07
  • Alright my solution was to just leave the containing object empty in the FXML and then programmatically add the scrollpane with the code area inside it. Not a great solution, but definitely the path of least resistance at this point. Thanks for looking at it with me. – Steve Jul 20 '17 at 17:06

1 Answers1

0

This worked for me. I used an AnchorPane as a root node.

    CodeArea codeArea = new CodeArea();
    VirtualizedScrollPane sp = new VirtualizedScrollPane(codeArea);

    anchorPane.getChildren().add(sp);

    anchorPane.setLeftAnchor(sp, 0.0);
    anchorPane.setRightAnchor(sp, 0.0);
    anchorPane.setBottomAnchor(sp, 0.0);
    anchorPane.setTopAnchor(sp, 0.0);

    codeArea.prefWidthProperty().bind(anchorPane.widthProperty());
    codeArea.prefHeightProperty().bind(anchorPane.heightProperty());