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

[ScrollPane] Control is not adjusting to the size of content.

    XMLWordPrintable

Details

    Description

      To reproduce run the app below:

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ButtonBuilder;
      import javafx.scene.control.ScrollPane;
      import javafx.scene.control.TextArea;
      import javafx.scene.control.TextAreaBuilder;
      import javafx.scene.control.TextField;
      import javafx.scene.control.TextFieldBuilder;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ScrollPaneTestDrive extends Application {

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

          @Override
          public void start(Stage stage) throws Exception {

              VBox topContainer = new VBox();
              topContainer.setMaxWidth(100d);
              topContainer.setMaxHeight(100d);
              topContainer.setStyle("-fx-border-color: blue;");
              
              Button button = ButtonBuilder.create().text("Press me").build();
              final TextField tf1 = TextFieldBuilder.create().text("0").build();
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent t) {
                      tf1.setText(String.valueOf(Integer.parseInt(tf1.getText()) + 1));
                  }
              });

              TextArea tf2 = TextAreaBuilder.create().prefHeight(100).build();
              for (int i = 0; i < 15; i++) {
                  tf2.appendText("text" + i + "\n");
              }
              Button empty = ButtonBuilder.create().text("This is empty-action button").build();

              topContainer.getChildren().addAll(button, tf1, tf2, empty);

              ScrollPane scrollPane = new ScrollPane();
              
              scrollPane.setContent(topContainer);

              Scene scene = new Scene(scrollPane, 300, 200);
              stage.setScene(scene);
              stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
              stage.show();
          }
      }

      Attachments

        Activity

          People

            miflemi Mick Fleming
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: