StyledTextArea scrolls to the caret every time span style is changed
See original GitHub issueI 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:
- Created 9 years ago
- Comments:13 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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!
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.