Skip navigation links
JavaFX 8
javafx.scene

Class Parent

javafx.scene.Node
    • javafx.scene.Parent
    • All Implemented Interfaces:
      Styleable, EventTarget
      Direct Known Subclasses:
      Group, Region, WebView


      public abstract class Parent
      extends Node
      The base class for all nodes that have children in the scene graph.

      This class handles all hierarchical scene graph operations, including adding/removing child nodes, marking branches dirty for layout and rendering, picking, bounds calculations, and executing the layout pass on each pulse.

      There are two direct concrete Parent subclasses

      • Group effects and transforms to be applied to a collection of child nodes.
      • Region class for nodes that can be styled with CSS and layout children.
      Since:
      JavaFX 2.0
    • Constructor Detail

      • Parent

        protected Parent()
        Constructs a new Parent.
    • Node> getChildrenUnmodifiable()
      Gets the list of children of this Parent as a read-only list.
      Returns:
      read-only access to this parent's children ObservableList
    • getManagedChildren

      protected <E extends NodeList<E> getManagedChildren()
      Gets the list of all managed children of this Parent.
      Type Parameters:
      E - the type of the children nodes
      Returns:
      list of all managed children in this parent
    • lookup

      public Node lookup(String selector)
      Description copied from class: IllegalStateException is thrown if this restriction is violated.

      Note to subclasses: if you override this method, you must return from your implementation the result of calling this super method. The actual list instance returned from any getChildren() implementation must be the list owned and managed by this Parent. The only typical purpose for overriding this method is to promote the method to be public.

      Returns:
      the list of children of this Parent.
    • getChildrenUnmodifiable

      public ObservableList<Node> getChildrenUnmodifiable()
      Gets the list of children of this Parent as a read-only list.
      Returns:
      read-only access to this parent's children ObservableList
    • getManagedChildren

      protected <E extends NodeList<E> getManagedChildren()
      Gets the list of all managed children of this Parent.
      Type Parameters:
      E - the type of the children nodes
      Returns:
      list of all managed children in this parent
    • lookup

      public Node lookup(String selector)
      Description copied from class: Node
      Finds this Node, or the first sub-node, based on the given CSS selector. If this node is a Parent, then this function will traverse down into the branch until it finds a match. If more than one sub-node matches the specified selector, this function returns the first of them.

      For example, if a Node is given the id of "myId", then the lookup method can be used to find this node as follows: scene.lookup("#myId");.

      Overrides:
      lookup in class Node
      Parameters:
      selector - The css selector of the node to find
      Returns:
      The first node, starting from this Node, which matches the CSS selector, null if none is found.
    • setNeedsLayout

      protected final void setNeedsLayout(boolean value)
      Sets the value of the property needsLayout.
      Property description:
      Indicates that this Node and its subnodes requires a layout pass on the next pulse.
    • isNeedsLayout

      public final boolean isNeedsLayout()
      Gets the value of the property needsLayout.
      Property description:
      Indicates that this Node and its subnodes requires a layout pass on the next pulse.
    • requestLayout

      public void requestLayout()
      Requests a layout pass to be performed before the next scene is rendered. This is batched up asynchronously to happen once per "pulse", or frame of animation.

      If this parent is either a layout root or unmanaged, then it will be added directly to the scene's dirty layout list, otherwise requestParentLayout will be invoked.

      Since:
      JavaFX 8.0
    • requestParentLayout

      protected final void requestParentLayout()
      Requests a layout pass of the parent to be performed before the next scene is rendered. This is batched up asynchronously to happen once per "pulse", or frame of animation.

      This may be used when the current parent have changed it's min/max/preferred width/height, but doesn't know yet if the change will lead to it's actual size change. This will be determined when it's parent recomputes the layout with the new hints.

    • prefWidth

      public double prefWidth(double height)
      Description copied from class: Node
      Returns the node's preferred width for use in layout calculations. If the node is resizable, its parent should treat this value as the node's ideal width within its range. If the node is not resizable, just returns its layoutBounds width, which should be treated as the rigid width of the node.

      Layout code which calls this method should first check the content-bias of the node. If the node has a vertical content-bias, then callers should pass in a height value that the preferred width should be based on. If the node has either a horizontal or null content-bias, then the caller should pass in -1.

      Node subclasses with a vertical content-bias should honor the height parameter whether -1 or a positive value. All other subclasses may ignore the height parameter (which will likely be -1).

      Overrides:
      prefWidth in class Node
      Parameters:
      height - the height that should be used if preferred width depends on it
      Returns:
      the preferred width that the node should be resized to during layout The result will never be NaN, nor will it ever be negative.
      See Also:
      Node.isResizable(), Node.getContentBias(), Node.autosize()
    • prefHeight

      public double prefHeight(double width)
      Description copied from class: Node
      Returns the node's preferred height for use in layout calculations. If the node is resizable, its parent should treat this value as the node's ideal height within its range. If the node is not resizable, just returns its layoutBounds height, which should be treated as the rigid height of the node.

      Layout code which calls this method should first check the content-bias of the node. If the node has a horizontal content-bias, then callers should pass in a width value that the preferred height should be based on. If the node has either a vertical or null content-bias, then the caller should pass in -1.

      Node subclasses with a horizontal content-bias should honor the height parameter whether -1 or a positive value. All other subclasses may ignore the height parameter (which will likely be -1).

      Overrides:
      prefHeight in class Node
      Parameters:
      width - the width that should be used if preferred height depends on it
      Returns:
      the preferred height that the node should be resized to during layout The result will never be NaN, nor will it ever be negative.
      See Also:
      Node.getContentBias(), Node.autosize()
    • minWidth

      public double minWidth(double height)
      Description copied from class: Node
      Returns the node's minimum width for use in layout calculations. If the node is resizable, its parent should not resize its width any smaller than this value. If the node is not resizable, returns its layoutBounds width.

      Layout code which calls this method should first check the content-bias of the node. If the node has a vertical content-bias, then callers should pass in a height value that the minimum width should be based on. If the node has either a horizontal or null content-bias, then the caller should pass in -1.

      Node subclasses with a vertical content-bias should honor the height parameter whether -1 or a positive value. All other subclasses may ignore the height parameter (which will likely be -1).

      If Node's Node.maxWidth(double) is lower than this number, minWidth takes precedence. This means the Node should never be resized below minWidth.

      Overrides:
      minWidth in class Node
      Parameters:
      height - the height that should be used if minimum width depends on it
      Returns:
      the minimum width that the node should be resized to during layout. The result will never be NaN, nor will it ever be negative.
      See Also:
      Node.isResizable(), Node.getContentBias()
    • minHeight

      public double minHeight(double width)
      Description copied from class: Node
      Returns the node's minimum height for use in layout calculations. If the node is resizable, its parent should not resize its height any smaller than this value. If the node is not resizable, returns its layoutBounds height.

      Layout code which calls this method should first check the content-bias of the node. If the node has a horizontal content-bias, then callers should pass in a width value that the minimum height should be based on. If the node has either a vertical or null content-bias, then the caller should pass in -1.

      Node subclasses with a horizontal content-bias should honor the width parameter whether -1 or a positive value. All other subclasses may ignore the width parameter (which will likely be -1).

      If Node's Node.maxHeight(double) is lower than this number, minHeight takes precedence. This means the Node should never be resized below minHeight.

      Overrides:
      minHeight in class Node
      Parameters:
      width - the width that should be used if minimum height depends on it
      Returns:
      the minimum height that the node should be resized to during layout The result will never be NaN, nor will it ever be negative.
      See Also:
      Node.isResizable(), Node.getContentBias()
    • computePrefWidth

      protected double computePrefWidth(double height)
      Calculates the preferred width of this Parent. The default implementation calculates this width as the width of the area occupied by its managed children when they are positioned at their current positions at their preferred widths.
      Parameters:
      height - the height that should be used if preferred width depends on it
      Returns:
      the calculated preferred width
    • computePrefHeight

      protected double computePrefHeight(double width)
      Calculates the preferred height of this Parent. The default implementation calculates this height as the height of the area occupied by its managed children when they are positioned at their current positions at their preferred heights.
      Parameters:
      width - the width that should be used if preferred height depends on it
      Returns:
      the calculated preferred height
    • computeMinWidth

      protected double computeMinWidth(double tent as needed.
    • getStylesheets

      public final ObservableList<String> getStylesheets()
      Gets an observable list of string URLs linking to the stylesheets to use with this Parent's contents. See Scene.getStylesheets() for details.

      For additional information about using CSS with the scene graph, see the CSS Reference Guide.

      Returns:
      the list of stylesheets to e>
      Calculates the min height of this Parent. The default implementation simply returns the pref height;
      Parameters:
      width - the width that should be used if min height depends on it
      Returns:
      the calculated min height
      Since:
      JavaFX 2.1
    JavaFX 8