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

Change content size in an Tab don't change size of parent TabPane

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 8u66
    • javafx
    • x86
    • windows_8

      FULL PRODUCT VERSION :
      1.8_66-x64

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.3.9600]

      A DESCRIPTION OF THE PROBLEM :
      i have a GridPane as content in a Tab
      if add many new Nods to the GridPane
      the GridPane changes its size

      but the TabPane don't change its size

      if you add an new Tab / switch to other Tab
      the TabPane calculates tis size correctly


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      - start the test
      - [add] new Tyb
      - [add] Label in Tab

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      TabPane must update itzs size to show alle created Labels

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package TabPaneLayout;

      import javafx.application.Application;
      import javafx.geometry.Pos;
      import javafx.scene.Node;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.Tab;
      import javafx.scene.control.TabPane;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.ColumnConstraints;
      import javafx.scene.layout.GridPane;
      import javafx.scene.layout.RowConstraints;
      import javafx.stage.Stage;

      /**
       * @author sst
       */
      public class TabPaneLayoutMain extends Application {

          private static final double MAX_VALUE = Double.MAX_VALUE;
          private static final double USE_PREF_SIZE = Double.NEGATIVE_INFINITY;
          private static final double USE_COMPUTED_SIZE = -1.0;

          /**
           * @param args
           */
          public static void main(String[] args) {
              launch(TabPaneLayoutMain.class, args);
          }

          @Override
          public void start(final Stage stage) throws Exception {
              final BorderPane root = new BorderPane();

              final TabPane tabs = new TabPane();
              tabs.setMinSize(USE_PREF_SIZE, USE_PREF_SIZE);
              tabs.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
              tabs.setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
              BorderPane.setAlignment(tabs, Pos.TOP_LEFT);
              
              final Button add = new Button("add");
              root.setTop(add);
              add.setOnAction((event) -> tabs.getTabs().add(new AddTab()));

              root.setCenter(tabs);
              stage.setScene(new Scene(root, 800, 800));
              stage.show();
          }

          private static final void changeTabPaneSize(final TabPane tabPane) {
              final int index = tabPane.getSelectionModel().getSelectedIndex();
              if (index < 0 || tabPane.getTabs().isEmpty()) {
                  return;
              }

              if (tabPane.getTabs().size() == 1) {
                  final Tab tab = tabPane.getTabs().remove(0);
                  tabPane.getTabs().add(tab);
              } else if (tabPane.getTabs().size() > 1 && index == 0) {
                  tabPane.getSelectionModel().select(1);
              } else if (tabPane.getTabs().size() > 1 && index != 0) {
                  tabPane.getSelectionModel().select(1);
              }

              tabPane.getSelectionModel().select(index);
          }

          private final class AddTab extends Tab {
              private final int[] column;
              private final GridPane grid;

              private AddTab() {
                  super(String.valueOf(System.currentTimeMillis()));

                  this.column = new int[]{0};

                  this.grid = new GridPane();
                  this.grid.setHgap(4);
                  this.grid.setVgap(4);
                  
                  this.grid.setMinSize(USE_PREF_SIZE, USE_PREF_SIZE);
                  this.grid.setPrefSize(USE_COMPUTED_SIZE, USE_COMPUTED_SIZE);
                  this.grid.setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);

                  this.grid.getRowConstraints().add(new RowConstraints(USE_PREF_SIZE, USE_COMPUTED_SIZE, USE_PREF_SIZE));

                  final Button add = new Button("add");
                  add.setOnAction((event) -> add(new Label("label")));
                  add(add);

                  setContent(this.grid);
              }

              private final void add(final Node node) {
                  GridPane.setConstraints(node, this.column[0]++, 0);
                  this.grid.getChildren().add(node);
                  this.grid.getColumnConstraints().add(new ColumnConstraints(USE_PREF_SIZE, USE_COMPUTED_SIZE, USE_PREF_SIZE));

                  if (getTabPane() != null) {
                      // workaround
                      // changeTabPaneSize(getTabPane());
                  }
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      change selection by code
      (i have a SelectionEvent on each Tab to load its content on first show)

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: