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.

2/5/2019 7:04:03 PM

Accepted Answer

Region is a superclass for components which have child nodes.

The difference is that Region doesn't allow to manipulate its children with the API. The Region.getChildren() method is protected, so you can't use it:

new Region().getChildren().add(...); // doesn't compile
new Pane().getChildren().add(...); // works

Why is that?

Because Region is dedicated for 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).

6/7/2015 8:44:24 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow