Package javafx.scene

Class Group

All Implemented Interfaces:
Styleable, EventTarget

@DefaultProperty("children") public class Group extends Parent
A Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.

A Group will take on the collective bounds of its children and is not directly resizable.

Any transform, effect, or state applied to a Group will be applied to all children of that group. Such transforms and effects will NOT be included in this Group's layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.

By default, a Group will "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should set autoSizeChildren to false and understand that if the preferred size of the children change, they will not automatically resize (so buyer beware!).

Group Example:

import javafx.scene.*;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import java.lang.Math;

Group g = new Group();
for (int i = 0; i < 5; i++) {
    Rectangle r = new Rectangle();
    r.setY(i * 20);
    r.setWidth(100);
    r.setHeight(10);
    r.setFill(Color.RED);
    g.getChildren().add(r);
}
Since:
JavaFX 2.0
  • Property Details

    • autoSizeChildren

      public final BooleanProperty autoSizeChildrenProperty
      Controls whether or not this Group will automatically resize any managed resizable children to their preferred sizes during the layout pass. If set to false, then the application is responsible for setting the size of this Group's resizable children, otherwise such nodes may end up with a zero width/height and will not be visible. This variable has no effect on content nodes which are not resizable (Shape, Text, etc).
      Default value:
      true
      See Also:
  • Constructor Details

    • Group

      public Group()
      Constructs a group.
    • Group

      public Group(Node... children)
      Constructs a group consisting of children.
      Parameters:
      children - children.
    • Group

      public Group(Collection<Node> children)
      Constructs a group consisting of the given children.
      Parameters:
      children - children of the group
      Throws:
      NullPointerException - if the specified collection is null
      Since:
      JavaFX 8.0
  • Method Details

    • setAutoSizeChildren

      public final void setAutoSizeChildren(boolean value)
      Sets the value of the autoSizeChildren property.
      Property description:
      Controls whether or not this Group will automatically resize any managed resizable children to their preferred sizes during the layout pass. If set to false, then the application is responsible for setting the size of this Group's resizable children, otherwise such nodes may end up with a zero width/height and will not be visible. This variable has no effect on content nodes which are not resizable (Shape, Text, etc).
      Default value:
      true
      Parameters:
      value - the value for the autoSizeChildren property
      See Also:
    • isAutoSizeChildren

      public final boolean isAutoSizeChildren()
      Gets the value of the autoSizeChildren property.
      Property description:
      Controls whether or not this Group will automatically resize any managed resizable children to their preferred sizes during the layout pass. If set to false, then the application is responsible for setting the size of this Group's resizable children, otherwise such nodes may end up with a zero width/height and will not be visible. This variable has no effect on content nodes which are not resizable (Shape, Text, etc).
      Default value:
      true
      Returns:
      the value of the autoSizeChildren property
      See Also:
    • autoSizeChildrenProperty

      public final BooleanProperty autoSizeChildrenProperty()
      Controls whether or not this Group will automatically resize any managed resizable children to their preferred sizes during the layout pass. If set to false, then the application is responsible for setting the size of this Group's resizable children, otherwise such nodes may end up with a zero width/height and will not be visible. This variable has no effect on content nodes which are not resizable (Shape, Text, etc).
      Default value:
      true
      Returns:
      the autoSizeChildren property
      See Also:
    • getChildren

      public ObservableList<Node> getChildren()
      Gets the list of children of this Group.
      Overrides:
      getChildren in class Parent
      Returns:
      the list of children of this Group.
    • prefWidth

      public double prefWidth(double height)
      Group defines the preferred width as simply being the width of its layout bounds, which in turn is simply the union of the layout bounds of all of its children. That is, the preferred width is the one that it is at, because a Group cannot be resized. Note: as the layout bounds in autosize Group depend on the Group to be already laid-out, this call will do the layout of the Group if necessary.
      Overrides:
      prefWidth in class Node
      Parameters:
      height - This parameter is ignored by Group
      Returns:
      The layout bounds width
      See Also:
    • prefHeight

      public double prefHeight(double width)
      Group defines the preferred height as simply being the height of its layout bounds, which in turn is simply the union of the layout bounds of all of its children. That is, the preferred height is the one that it is at, because a Group cannot be resized. Note: as the layout bounds in autosize Group depend on the Group to be already laid-out, this call will do the layout of the Group if necessary.
      Overrides:
      prefHeight in class Node
      Parameters:
      width - This parameter is ignored by Group
      Returns:
      The layout bounds height
      See Also:
    • layoutChildren

      protected void layoutChildren()
      Group implements layoutChildren such that each child is resized to its preferred size, if the child is resizable. Non-resizable children are simply left alone. If autoSizeChildren is false, then Group does nothing in this method.
      Overrides:
      layoutChildren in class Parent