Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8091294

With keyboard nav, ScrollPane does not autoscroll to ensure focused control is visible

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u21
    • javafx
    • linux

      I have a scrollPane which has various TitledPane into this, each TitledPane has various textfield's as children. When i navigate throughout textfield's using Tab key, the scrollpane do not autoscroll to ensure visible the control gaining focus. This is a program demonstrating the problem.

      import java.util.Random;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ScrollPane;
      import javafx.scene.control.TextField;
      import javafx.scene.control.TitledPane;
      import javafx.scene.layout.AnchorPane;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ScrollPaneEnsureVisible extends Application {

          private static final Random random = new Random();

          @Override
          public void start(Stage primaryStage) {

              VBox root = new VBox();
              ScrollPane scrollPane = new ScrollPane();
              Pane content = new Pane();
              scrollPane.setContent(content);

              for (int i = 0; i < 3; i++) {
                  TitledPane pane = new TitledPane();
                  AnchorPane paneContent = new AnchorPane();
                  for (int j = 0; j < 2; j++) {
                      TextField text = new TextField();
                      paneContent.getChildren().add(text);
                      text.setLayoutX(8);
                      text.setLayoutY(j*30);
                  }
                  pane.setCollapsible(false);
                  pane.setContent(paneContent);
                  pane.setLayoutY(i*100);
                  content.getChildren().add(pane);
              }

              root.getChildren().add(scrollPane);

              scrollPane = new ScrollPane();
              content = new Pane();
              scrollPane.setContent(content);
              for (int i = 0; i < 3; i++) {
                  TitledPane pane = new TitledPane();
                  AnchorPane paneContent = new AnchorPane();
                  pane.setContent(paneContent);
                  pane.setPrefWidth(200);
                  pane.setPrefHeight(80);
                  pane.setCollapsible(false);
                  pane.setLayoutY(i*100);
                  content.getChildren().add(pane);
              }

              root.getChildren().add(scrollPane);


              Scene scene = new Scene(root, 300, 250);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

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

      For the second titledpane all is fine, but for first not. i need to ensure visible (autoscroll the scrollpane) that controls when they gain focus.

            Unassigned Unassigned
            duke J. Duke
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: