java javaFX 中的 Pane 和 stackPane 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41202468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the difference between Pane and stackPane in javaFX?
提问by Asaad Maher
I was learning javafx and came across these two statements which I don't know their difference.
我正在学习 javafx 并遇到了这两个我不知道它们区别的语句。
Pane pane = new Pane();
and
和
StackPane pane = new StackPane();
Can somebody enlighten me about the difference and when to use which?
有人可以启发我了解差异以及何时使用哪个吗?
回答by Bo Halim
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
两者都是布局但thePane
是所有其他布局的基础,不同之处在于Pane提供了节点的自由定位,而The StackPane
(以及其他带有Pane后缀的Node称为Built-in Layout)作为回报,遵循自己的逻辑(位置/约束...)。例如,“StackPane”将其子项布置在从后到前的堆栈StackPane 中。这只是表面和有限的信息,这里有一个很好的教程:JavaFX 中的布局
回答by fabian
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.
Pane
不做任何定位。孩子的layoutX
和layoutY
保持不变。此外,可调整大小的孩子被调整到他们喜欢的大小。
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...
StackPane
StackPane
如果没有为孩子设置位置,则根据为孩子本身设置的对齐方式或为自己设置的对齐方式来确定孩子的位置。可调整大小的孩子被调整为StackPane
最适合's 大小的大小(仍然考虑最大大小)。两者都可以通过为单个孩子设置的边距进行修改......