RichTextFX: Caret Position = InlineCssTextArea .getText().length() but it doesn't scroll vertically to the bottom

  • Java Version: jdk1.8.0_112

  • RichTextFX Version: richtextfx-fat-0.6.10.jar

I am using :

InlineCssTextArea textArea = new InlineCssTextArea();
textArea.setEditable(false);
textArea.setFocusTraversable(false);

and i am trying to scroll programmatically at the bottom :

//It returns the maximum length of the InlineCssTextArea  `text`
System.out.println(textArea.getText().length());
System.out.println(textArea.getCaretPosition());
   		    
//It doesn't scroll to the end
textArea.positionCaret(textArea.getText().length());

The problem is that the length of InlineCssTextArea text is 830 even if the caret is positioned at 830 it doesn’t scroll to the bottom…

screenshot49984

Is it a bug?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (10 by maintainers)

Most upvoted comments

So the issue is maybe done … 😃

Also, I exposed more API in #418 that can accomplish what you desire with show-related methods. For example:

InlineCssTextArea area = // creation code;
area.showParagraphAtBottom(area.getParagraphs().size() - 1);

However, we haven’t made a new release with that code yet.

Try this code. I noticed that when wrapText is false, the virtualflow will scroll to the second-to-last line. I’m not entirely sure why that occurs, but it might be due to that line having no content on it. Regardless, when wrapText is true, it works as expected. (I also made the area editable and request focus after the stage is shown, so one can see the position of the caret).

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.InlineCssTextArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;

/**
 * @author Alexander
 *
 */
public class Tester extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        primaryStage.setTitle("Testing InlineCssTextArea Vertical ScrollBar");

        // --------------------------------------------------
        InlineCssTextArea textArea = new InlineCssTextArea();
//        textArea.setEditable(false);
        textArea.setFocusTraversable(false);
        textArea.setMinSize(500, 200);
//        textArea.setWrapText(true);

        VirtualizedScrollPane<InlineCssTextArea> vsPane = new VirtualizedScrollPane<>(textArea);

        vsPane.setMaxWidth(Double.MAX_VALUE);
        vsPane.setMaxHeight(Double.MAX_VALUE);
        GridPane.setVgrow(vsPane, Priority.ALWAYS);
        GridPane.setHgrow(vsPane, Priority.ALWAYS);

        // -------root
        GridPane root = new GridPane();
        root.setMaxWidth(Double.MAX_VALUE);
        root.setMaxHeight(Double.MAX_VALUE);
        root.add(vsPane, 0, 0);

        // Append some text to the textArea
        for (int i = 0; i < 200; i++)
            textArea.appendText("I is [" + i
                    + "] some text some text some text some textsome text some text text some text text some text text some text text some text text some text text some text\n");

        // Below I am trying to move the Vertical ScrollBar to the Bottom
        textArea.moveTo(textArea.getLength());
        textArea.requestFollowCaret();

        // -------------------------------------------------

        // Scene
        Scene scene = new Scene(root, 500, 200);

        // Show Stage
        primaryStage.setScene(scene);
        primaryStage.show();

        // focus area so can see the caret
        textArea.requestFocus();
    }

    public static void main(String[] args) {
        launch(args);
    }

}

In the 0.7-M3 release, you’ll use the code:

area.moveTo(area.getLength());
area.requestFollowCaret();

Are you using positionCaret intentionally? The right way to move the caret is via moveTo (I don’t know if that will fix your problem).