In JavaFX, what is the difference between a Pane
and a Group
? I can't make out any difference.
What is the difference between a Pane and a Group?
30.3k views Asked by Florian At
3
There are 3 answers
0
On
Also, note that Group was designed to be very lightweight and doesn't support a lot of styles. For example, you can't set border or background color for the group.
See this answer for more details.
A
Group
is not resizable (meaning that its size is not managed by its parent in the scene graph), and takes on the union of the bounds of its child nodes. (So, in other words, the local bounds of aGroup
will be the smallest rectangle containing the bounds of all the child nodes). If it is larger than the space it is allocated in its parent, it will be clipped.By contrast, a
Pane
is resizable, so its size is set by its parent, which essentially determine its bounds.Here is a quick demo. The
Group
is on top and thePane
below. Both contain a fixed blue square at(100,100)
and a green square which is moved by pressing the left/right arrow keys. Note how at the beginning, the blue square appears in the top left corner of the group, because the local bounds of the group start at the top-leftmost point of all its child nodes (i.e. the local bounds of the group extend from(100, 100)
right and down). As you move the green rectangles "off screen", the group adjusts its bounds to incorporate the changes, wherever possible, whereas the pane remains fixed.