Skip to content

Javafx Pane vs Region?

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 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).

3 People found this is helpful