javafx-2 – 为什么我的JavaFX HBox中的孩子不会成长(SceneBuilder)?

JavaFX docs for HBox说:

If an hbox is resized larger than its preferred width, by default it will keep children to their preferred widths, leaving the extra space unused. If an application wishes to have one or more children be allocated that extra space it may optionally set an hgrow constraint on the child. See “Optional Layout Constraints” for details.

在附图中,为什么按钮不是填充水平宽度?

不是和文档引用的HBox.setHgrow(field,Priority.ALWAYS)代码相同.

最佳答案
选择您的按钮,就像您在屏幕截图中所做的那样,右侧的“布局”窗格中的“大小”框将“最大宽度”设置为:

MAX_VALUE

这将阻止按钮的最大大小被绑定到按钮的首选大小.

见Oracle的Tips for Sizing and Aligning Nodes

UI controls also provide default minimum and maximum sizes that are based on the typical usage of the control. For example, the maximum size of a Button object defaults to its preferred size because you don’t usually want buttons to grow arbitrarily large.

….

To enable all of the buttons to be resized to the width of the VBox pane, the maximum width of each button is set to the Double.MAX_VALUE constant, which enables a control to grow without limit. An alternative to using the maximum value constant is to set the maximum width to a specific value, such as 80.0.

转载注明原文:javafx-2 – 为什么我的JavaFX HBox中的孩子不会成长(SceneBuilder)? - 代码日志