尽管设置了 maxWidth 属性,AnchorPane 仍在继续增长

AnchorPane keeps growing despite having maxWidth property set

我正在构建简单的 GUI,其中根元素 StackPane 有两个子元素:HBoxAnchorPane

将所有子组件的 maxWidth 属性 设置为 600 后,当我只向其添加任何组件并设置该组件的 AnchorPane 时,AnchorPane 似乎仍然水平增长锚定到超出 600.

的值

如您在上面的屏幕截图中所见 - 右下角的 Label 已将左锚点设置为 700,这导致 AnchorPane 宽度增加。

我宁愿将此 Label 剪切或放置在可见之外 space。

这是为什么?我可以以某种方式强制 AnchorPane 保持其最大界限吗?这个问题有解决办法吗?

您可以找到相关的 java(fx) 代码 here

我不知道为什么,但是,我在 SceneBuilder 中测试了它并更改了 fxml 中的一些属性并且它起作用了。我将 minWidth 添加到 StackPaneAnchorPane。 这是我的 fork.