Package javafx.scene

Class Parent

java.lang.Object
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
  • Property Details

  • Constructor Details

    • Parent

      protected Parent()
      Constructs a new Parent.
  • Method Details

    • getChildren

      protected ObservableList<Node> getChildren()
      Gets the list of children of this Parent.

      See the class documentation for Node for scene graph structure restrictions on setting a Parent's children list. If these restrictions are violated by a change to the list of children, the change is ignored and the previous value of the children list is restored. An IllegalArgumentException is thrown in this case.

      If this Parent node is attached to a Scene attached to a Window that is showning (Window.isShowing()), then its list of children must only be modified on the JavaFX Application Thread. An 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 Node> List<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
    • 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.
    • needsLayoutProperty

      public final ReadOnlyBooleanProperty needsLayoutProperty()
      Indicates that this Node and its subnodes requires a layout pass on the next pulse.
      See Also:
    • 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.

    • 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 height)
      Calculates the minimum width of this Parent. The default implementation simply returns the pref width.
      Parameters:
      height - the height that should be used if min width depends on it
      Returns:
      the calculated min width
      Since:
      JavaFX 2.1
    • computeMinHeight

      protected double computeMinHeight(double width)
      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
    • getBaselineOffset

      public double getBaselineOffset()
      Calculates the baseline offset based on the first managed child. If there is no such child, returns Node.getBaselineOffset().
      Overrides:
      getBaselineOffset in class Node
      Returns:
      baseline offset
    • layout

      public final void layout()
      Executes a top-down layout pass on the scene graph under this parent. Calling this method while the Parent is doing layout is a no-op.
    • layoutChildren

      protected void layoutChildren()
      Invoked during the layout pass to layout the children in this Parent. By default it will only set the size of managed, resizable content to their preferred sizes and does not do any node positioning.

      Subclasses should override this function to layout content 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 use with this Parent
      Since:
      JavaFX 2.1
    • updateBounds

      protected void updateBounds()
      Updates the bounds of this Parent and its children.