2 Replies Latest reply on Aug 21, 2013 3:00 PM by 0ba15464-6294-40de-bcf8-7cd809e203bc

    Access to TextArea's Scroll Pane or Scroll Bars


      I am trying to get notified by the TextArea to tell me when the scrolling has reached the bottom.  I know I can do this with ScrollPane's vvalueProperty, but I don't have access to that in the TextArea.  is there a way to get at this or to know when the scrolling has stopped and I can check the location of the scroll?  I tries the TextAreas onScrollFinished with out any success.  It never fired the event except when the mouse wheal tried to over scroll when it was already at the bottom.

        • 1. Re: Access to TextArea's Scroll Pane or Scroll Bars

          You can get the ScrollPane via a lookup. I don't really like recommending lookups, but sometimes there seems to be no other way; and in this case the css structure is at least documented in the css reference.



          import javafx.application.Application;
          import javafx.beans.binding.Bindings;
          import javafx.scene.Scene;
          import javafx.scene.control.Label;
          import javafx.scene.control.ScrollPane;
          import javafx.scene.control.TextArea;
          import javafx.scene.layout.BorderPane;
          import javafx.stage.Stage;
          public class TextAreaScrollTest extends Application {
            public void start(Stage primaryStage) {
            final BorderPane root = new BorderPane();
            final TextArea textArea = new TextArea();
            final Label label = new Label();
            primaryStage.setScene(new Scene(root, 400, 300));
            ScrollPane scrollPane = (ScrollPane) textArea.lookup(".scroll-pane");
            label.textProperty().bind(Bindings.format("Vertical scroll at %.3f", scrollPane.vvalueProperty()));
            public static void main(String[] args) {


          Be careful when you call textArea.lookup(...). The text area needs to have had css styles applied in order for this to work; typically this means it has been attached to a scene which is displayed in a stage. (If you move the lookup call above to just before the call to primaryStage.show(), for example, you will get a nice NullPointerException.)

          • 2. Re: Access to TextArea's Scroll Pane or Scroll Bars

            Worked like a charm.  thanks for your help!!!