question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StyledTextArea scrolls to the caret every time span style is changed

See original GitHub issue

I have a StyleClassedTextArea and load a String into it. I have a button event which calls setStyleClass a number of times using data external to the document. For some reason, when I call it, the text area always automatically scrolls to the bottom of the document. I have tried all kinds of variations, but it happens. Also, when I make the setStyleClass dependent on the document’s content changing and I edit the text in the middle of the text field, it scroll-jumps into a position where the line I am editing becomes the bottom-most line in the view. What am I doing wrong?

Thanks,

Matthias


Minimal Code Example (just paste a lot of text into the field and click the button and provide some stylesheet in the css file defining a ‘red’ style):


package application;

//imports ...

public class Main extends Application {

private Scene scene;
private StyleClassedTextArea textArea;

@Override
public void start(Stage stage) {

    stage.setTitle("ScrollTest);

    try {
        BorderPane root = new BorderPane();
        textArea = new StyleClassedTextArea();
        textArea.setWrapText(true);

        BorderPane border = new BorderPane();
        HBox topBox = new HBox();

        Button updateButton = new Button("foo");            
        updateButton.setPrefSize(100, 20);
        updateButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override public void handle(ActionEvent e) {
                textArea.setStyleClass(5, 10, "red");
            }
        });


        topBox.getChildren().addAll(updateButton);

        scene = new Scene(border, 600, 400);
        border.setCenter(textArea);

        border.setTop(topBox);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());

        stage.setScene(scene);
        stage.show();

    } catch(Exception e) {
        e.printStackTrace();
    }
}

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mgrabmaircommented, Jun 9, 2016

@TomasMikula I am happy to see this is being picked up. My project ended up being abandoned, so I did not get back to this, but it is good to hear that this is a possibility. Thanks for the help!

0reactions
JordanMartinezcommented, Oct 4, 2016

It might be something else than Point2D, to account for the case when the caret is out of view (and in that case indicates whether it is before or after the currently displayed text). Also, it would be more like Bounds than Point2D anyway.

I forgot that sometimes the position of the anchor can change as well (is it in relation to the caret? Or the end of the selection?) Yeah, Bounds makes more sense.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GenericStyledArea (richtextfx 0.10.3 API) - javadoc.io
Auto-Scrolling to the Caret. Every time the underlying EditableStyledDocument changes via user interaction (e.g. typing) through the GenericStyledArea ...
Read more >
GenericStyledArea (richtextfx 0.8.0 API) - FXMisc
Auto-Scrolling to the Caret. Every time the underlying EditableStyledDocument changes via user interaction (e.g. typing) through the StyledTextArea ...
Read more >
How do I stop cursor moving to the start every time innerHTML ...
I have a function that separates words into separate span tags and updates the div I am typing into but every time ......
Read more >
text area change dimension Code Example - Code Grepper
<textarea rows="10" style="font-size:2vw; width:100%;"></textarea> ... html css js make text area rezise not scroll and nto move sroll · scaleable textarea ...
Read more >
org.fxmisc.richtext.GenericStyledArea java code examples
sameAs(targetLine)) { // compute new caret position CharacterHit hit ... getStylesheets().add(StyledTextArea.class. ... replaceAbsolutely(change.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found