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

Ability to get the enclosing ToolBar from a Node in the list of ToolBar items

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      generic

      Description

      FULL PRODUCT VERSION :
      Tested on several different versions, all gives the same result:
      JDK 8.0.131 (on Windows)
      JDK 8.0.172 (early access, on Windows)
      JDK 9.0.4 (on Windows)
      OpenJDK 8.0.151 and OpenJFK 8.0.60 (Ubuntu 16.04 inside VirtualBox)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.16299.309]
      Linux stekeblad-VirtualBox 4.13.0-37-generic #42~16.04.1-Ubuntu SMP Wed Mar 7 16:03:28 UTC 2018 x86_64 x86 64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Executed from inside IntelliJ IDEA 2017.3.5 (Community Edition)

      A DESCRIPTION OF THE PROBLEM :
      Calling toolbar.getChildrenUnmodifiable() on a ToolBar with one or more items in it (eg. buttons) returns no results and when calling button.getParent().getId() on a Button inside a ToolBar generates a NullPointerException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a simple JavaFx application with a ToolBar and a button inside the ToolBar.
      Give both of them Ids.
      In the controller try call getParent().getId() on the button and check the returned result of getChildrenUnmodifiable() on the ToolBar

      Code for a JavaFx controller class and a window fxml file is attached in the code section, a Main class and the imports for the Controller is not included to keep it short.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected output of the attached code:
      Window is AnchorPane[id=window]
      Toolbar is ToolBar[id=toolbar, styleClass=tool-bar]
      Button_Toolbar is Button[id=button_toolbar, styleClass=button]'Button'
      Button_Window is: Button[id=button_window, styleClass=button]'Button'

      The id of the button_toolbar's parent is: toolbar
      The id of the button_window's parent is: window
      The id of the toolbar's parent is: window

      The ids of the toolbar's children is:
      - button_toolbar
      The ids of the window's children is:
      - toolbar
      - button_window
      ACTUAL -
      Window is AnchorPane[id=window]
      Toolbar is ToolBar[id=toolbar, styleClass=tool-bar]
      Button_Toolbar is Button[id=button_toolbar, styleClass=button]'Button'
      Button_Window is: Button[id=button_window, styleClass=button]'Button'

      Actual output of the attached code:
      Failed finding parent of button_toolbar
      The id of the button_window's parent is: window
      The id of the toolbar's parent is: window

      The ids of the toolbar's children is:
      The ids of the window's children is:
      - toolbar
      - button_window

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Controller implements Initializable {

          public ToolBar toolbar;
          public Button button_toolbar;
          public Button button_window;
          public AnchorPane window;

          @Override
          public void initialize(URL location, ResourceBundle resources) {
              System.out.println("Window is " + window); // null checks
              System.out.println("Toolbar is " + toolbar);
              System.out.println("Button_Toolbar is " + button_toolbar);
              System.out.println("Button_Window is: " + button_window + "\n");

              try { // Try get the parent of the button_toolbar
                  System.out.println("The id of the button_toolbar's parent is: " + button_toolbar.getParent().getId());
              } catch (Exception e) {
                  System.out.println("Failed finding parent of button_toolbar");
              }
              try { // Try get the parent of the button_window
                  System.out.println("The id of the button_window's parent is: " + button_window.getParent().getId());
              } catch (Exception e) {
                  System.out.println("Failed finding parent of button_window");
              }
              try { // Try get the parent of the toolbar
                  System.out.println("The id of the toolbar's parent is: " + toolbar.getParent().getId());
              } catch (Exception e) {
                  System.out.println("Failed finding parent of toolbar");
              }

              // Try get the children of the toolbar
              System.out.println("\nThe ids of the toolbar's children is: ");
              for (Node child : toolbar.getChildrenUnmodifiable()) {
                  System.out.println("- " + child.getId());
              }
              // Try get children of window
              System.out.println("The ids of the window's children is: ");
              for (Node child : window.getChildrenUnmodifiable()) {
                  System.out.println("- " + child.getId());
              }
          }
      }

      <?xml version="1.0" encoding="UTF-8"?>

      <?import javafx.scene.control.Button?>
      <?import javafx.scene.control.ToolBar?>
      <?import javafx.scene.layout.AnchorPane?>

      <AnchorPane fx:id="window" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Controller">
         <children>
            <ToolBar fx:id="toolbar" layoutX="29.0" layoutY="14.0" prefHeight="40.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
              <items>
                <Button fx:id="button_toolbar" mnemonicParsing="false" text="Button" />
              </items>
            </ToolBar>
            <Button fx:id="button_window" layoutX="14.0" layoutY="40.0" mnemonicParsing="false" text="Button" />
         </children>
      </AnchorPane>
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Access the Nodes inside the toolbar directly instead of through the toolbar

        Attachments

        1. Controller.java
          2 kB
        2. fxml.fxml
          0.8 kB
        3. Main.java
          0.6 kB

          Activity

            People

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

              Dates

              • Created:
                Updated: