According to the documentation, both Region and Pane will resize any resizable child nodes to their preferred size, but will not reposition them.
So i can't see where the differencies between these two containers remain and when use one or another.
Region is the base class for all JavaFX Node-based UI Controls, and all layout containers. It is a resizable Parent node which can be styled from CSS. It can have multiple backgrounds and borders. It is designed to support as much of the CSS3 specification for backgrounds and borders as is relevant to JavaFX.
Layout panes are containers which are used for flexible and dynamic arrangements of UI controls within a scene graph of a JavaFX application. As a window is resized, the layout pane automatically repositions and resizes the nodes it contains.
HBox is a subclass of Pane that lays out its children next to each other, in a horizontal row. VBox is a subclass of Pane that lays out its children in vertical column. An HBox might be used as the bottom component in a BorderPane, making it possible to line up several components along the bottom of the border pane.
The Scene it self can only have one root Pane. So if you want 2 panes in the Scene you need 3. In your code this can look like this: StackPane rootPane = new StackPane(); Scene scene = new Scene(rootPane,...); Pane pane1 = new Pane(); Pane pane2 = new Pane(); rootPane.
Region
is a superclass for components that have child nodes.
The difference is that Region
doesn't allow to manipulate its children through the public API. The Region.getChildren()
method is protected:
new Region().getChildren().add(...); // doesn't compile
new Pane().getChildren().add(...); // works
Why is that?
Because Region
is dedicated to component developers, and it allows them to choose if they want to allow API users to work with children directly (like Pane
, HBox
, etc.) or not (like charts).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With