1

I want to disable the Auto Scrolling of TextArea in javaFx, Because when I add text to TextArea the scroll is moving down, I don't want to Auto Scroll the Scroll bar in TextArea, if I add the text scroll should be selected position.(Example if user is reading middle line if add the text it Automatically going to down, So again user need to move the scroll to middle line). So for that reason I want to disable the Auto Scroll in TextArea in JavaFx.

javafx.application.Platform.runLater( new Runnable() {
  @Override
  public void run() {
  logTextArea.appendText("I am adding text here to TextArea"+"\n");// Adding the text to logTextArea
   }
});

Below are the ref links :- please check this link

Please Check this link also

Community
  • 1
  • 1
epn
  • 83
  • 1
  • 3
  • 12
  • http://stackoverflow.com/questions/30573461/auto-scroll-down-a-textarea see in this link when he append the text scroll bar automatically going down, i don't want like that. where ever user keep the scroll bar that should be there after appending the text aslo. – epn Dec 12 '16 at 09:12

1 Answers1

1

From How can I hide the scroll bar in TextArea?:

Remove Horizontal Scrollbar

textArea.setWrapText(true);

Remove Vertical Scrollbar

ScrollBar scrollBarv = (ScrollBar)ta.lookup(".scroll-bar:vertical");
scrollBarv.setDisable(true);

CSS

.text-area .scroll-bar:vertical:disabled {
    -fx-opacity: 0;
}

Example:

public class Test2 extends Application {

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

@Override
public void start(Stage primaryStage) {
    TextArea textArea = new TextArea("This is my message");
    textArea.setWrapText(true);
    String css = this.getClass().getResource("/ta.css").toExternalForm();
    textArea.getStylesheets().add(css);
    primaryStage.setScene(new Scene(textArea));
    primaryStage.show();
    ScrollBar scrollBar = (ScrollBar) textArea.lookup(".scroll-bar:vertical");
    scrollBar.setDisable(true);

}

}
saeid rastak
  • 325
  • 2
  • 11
  • if i use ScrollBar scrollBarv = (ScrollBar)ta.lookup(".scroll-bar:vertical"); scrollBarv.setDisable(true);in controller public void initialize(URL url, ResourceBundle rb) method i am getting Nullpointer Exception. because i am getting scrollPane after adding some text. if i use css there is no exception but there is no change.My requirement is after adding text more the auto scrollPane will came in that i don't want go scrollbar automatically down. where ever user keep the scrollBar that should be there after adding the text also. – epn Dec 12 '16 at 09:01
  • http://stackoverflow.com/a/30591681/5824797 see in this link when he append the text scroll bar automatically going down, i don't want like that. where ever user keep the scroll bar that should be there after appending the text aslo. – epn Dec 12 '16 at 09:06
  • you must use this codes after showing stage. i update the answer . let me know. – saeid rastak Dec 12 '16 at 10:09
  • I am getting same Exception, Provide Complete Example – epn Dec 12 '16 at 10:36