I have JavaFX TextFlowwrapped in ScrollPane, and I'm trying to automatically scroll it down when a new one is Textadded to TextFlow.
I tried connecting listeners, maximizing ScrollPane vvalueto:
- Property
ScrollPane vvalue.- This blocks the
ScrollPanebottom, which is undesirable.
- Property
ScrollPane viewportBounds. - List of children
TextFlow.- This scrolls to the place that was below before the last was added
Text, oddly enough. I tried explicitly requesting the layout before scrolling, but this had no effect.
Thank you very much, I would like to scroll so that if the new addition is too large to display immediately, scroll ScrollPane, so the new addition is at the top and the user must scroll manually to see the "overflow". As I said, this will be an additional bonus, just scrolling to the bottom will be very good, since I do not expect such big additions (regularly).
And no, I do not go to TextAreawhere it would be relatively simple. I want to be able to easily add plain, bold and italic text to TextFlow, rather TextAreathan supporting this. I also tried Thomas Mikula RichTextFX , but
- He continued throwing
StackOverflowErrorthrough the internal code without explanation. - .
, TextFlow, .
: , :
private ScrollPane textContainer;
private TextFlow text;
public BaseGui() {
text.getChildren().addListener(
(ListChangeListener<Node>) ((change) -> {
text.layout();
textContainer.layout();
textContainer.setVvalue(1.0f);
}));
textContainer.setContent(text);
}
public void appendBold(String msg) {
append(msg, "-fx-font-weight: bold");
}
private synchronized void append(String msg, String style) {
Platform.runLater(() -> {
Text t = new Text(msg);
t.setFont(segoe(13));
if (!style.equals("")) {
t.setStyle(style);
}
text.getChildren().add(t);
});
}
, , .