Asaad Maher
Asaad Maher

Reputation: 111

what is the difference between Pane and stackPane in javaFX?

I was learning javafx and came across these two statements which I don't know their difference.

Pane pane = new Pane();

and

StackPane pane = new StackPane();

Can somebody enlighten me about the difference and when to use which?

Upvotes: 9

Views: 16909

Answers (2)

Bo Halim
Bo Halim

Reputation: 1776

Both are layouts but the Pane is the basis of all the other layouts, the difference is that the Pane offers a free positioning of nodes, and The StackPane (and other Node with the suffix Pane called Built-in Layout) in return, follow their own logic (Positions/Constraints...). The 'StackPane' for example lays out its children in a back-to-front stack StackPane. This is only superficial and limited information, here's a good tutorial : Layout in JavaFX

Upvotes: 10

fabian
fabian

Reputation: 82461

The difference between both layouts is positioning of the children and the resizing of resizeable children.

Pane does not do any positioning. The child's layoutX and layoutY are left unmodified. Furthermore resizeable children are resized to their preferred sizes.

StackPane determines the position of children based on the alignment set for the child itself or the one set for the StackPane itself, if no position is set for the child. Resizable children are resized to a size that fits the StackPane's size best (still taking into account max size). Both can be modified by a margin set for individual children...

Upvotes: 5

Related Questions