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

[ToolBar] Overflow button of ToolBar doesn't appear when the size of the items increases

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_74"
      Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
      Java HotSpot(TM) Client VM (build 25.74-b02, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      If the width of the items of a horizontal ToolBar of fixed size increases after they were added and after a layout pass has happened, the overflow button won't appear even when it would then be necessary. As layout is still performed, the wider elements are displayed but some of them are placed outside of the ToolBar.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a horizontal ToolBar with some items and with a fixed size which is chosen such that the overflow button doesn't appear (as in the code below).
      2. Ensure that a layout pass has happened by displaying the ToolBar.
      3. Increase the width of the items (by clicking on the button of the example) such that not all of the items fit in the ToolBar anymore.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The overflow button should appear and some of the items should be moved to the menu.
      ACTUAL -
      The overflow button does not appear. Instead, the items of the ToolBar are displayed beyond the ToolBar.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.List;
      import java.util.stream.Collectors;
      import java.util.stream.IntStream;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.ToolBar;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.Region;
      import javafx.stage.Stage;

      public class ToolbarOverflowTester extends Application {

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

          @Override
          public void start(Stage primaryStage) {
              List<Label> labels = createLabels(10);

              ToolBar toolBar = new ToolBar();
              toolBar.getItems().addAll(labels);

              Button increaseWidthButton = new Button("Increase width of labels");
              increaseWidthButton.setOnAction(event -> labels.forEach(label -> label.setPrefWidth(55.0)));

              toolBar.setMinWidth(Region.USE_PREF_SIZE);
              toolBar.setPrefWidth(200);
              toolBar.setMaxWidth(Region.USE_PREF_SIZE);
              Pane rootPane = new HBox(toolBar, increaseWidthButton);

              Scene scene = new Scene(rootPane, 400, 100);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          private List<Label> createLabels(int number) {
              return IntStream.rangeClosed(1, number)
                      .mapToObj(String::valueOf)
                      .map(this::createLabel)
                      .collect(Collectors.toList());
          }

          private Label createLabel(String text) {
              Label label = new Label(text);
              label.setStyle("-fx-border-width: 1; -fx-border-color: deepskyblue");
              label.setMinSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
              label.setMaxSize(Region.USE_PREF_SIZE, Region.USE_PREF_SIZE);
              return label;
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: