如何修复 Scene Builder 中的 window 大小?
How to fix the window size in Scene Builder?
我这里设置了max/minwidth/height
但它似乎没有用,我仍然可以在预览时更改 window 的大小
你可以在舞台上设置.setResizable(false);
,应该会有帮助。
您设置的值(可能)是根 Node
。这不会阻止 Scene
或 Stage
增长或收缩超过指定值。事实上,根据根 Node
,设置这些值甚至不会阻止 Node
增长或收缩。
来自 Scene
的 Javadoc:
The application must specify the root Node for the scene graph by setting the root property. If a Group is used as the root, the contents of the scene graph will be clipped by the scene's width and height and changes to the scene's size (if user resizes the stage) will not alter the layout of the scene graph. If a resizable node (layout Region or Control) is set as the root, then the root's size will track the scene's size, causing the contents to be relayed out as necessary.
如果您想限制 Stage
的大小,您需要在代码中设置 Stage
的适当属性:minWidth
、minHeight
、maxWidth
和 maxHeight
。由于您正在设置 minWidth = maxWidth
和 minHeight = maxHeight
,因此最好使用 Stage.setResizable(false)
(如 中所述)。此选项还可以防止 Stage
最大化,而设置 min/max 大小属性不会。虽然在我的机器上属性 do 阻止 Stage
在最大化时增长,但它会导致 Stage
跳到左上角。
由于您无权访问 Scene Builder 使用的预览 Stage
(据我所知),我认为您无法限制预览的大小。但是,您可能需要处理的一件事是预览 Stage
在关闭时打开到之前的大小。我不确定为什么这是 default/unchangeable 行为,但我 猜测 这是由于每次使用相同的 Stage
造成的。要将 Stage
调整为您喜欢的大小,您可以转到:
Preview -> Preview Size -> Preferred Size (Width x Height)
这需要显示预览,否则菜单项将被禁用。
我这里设置了max/minwidth/height
但它似乎没有用,我仍然可以在预览时更改 window 的大小
你可以在舞台上设置.setResizable(false);
,应该会有帮助。
您设置的值(可能)是根 Node
。这不会阻止 Scene
或 Stage
增长或收缩超过指定值。事实上,根据根 Node
,设置这些值甚至不会阻止 Node
增长或收缩。
来自 Scene
的 Javadoc:
The application must specify the root Node for the scene graph by setting the root property. If a Group is used as the root, the contents of the scene graph will be clipped by the scene's width and height and changes to the scene's size (if user resizes the stage) will not alter the layout of the scene graph. If a resizable node (layout Region or Control) is set as the root, then the root's size will track the scene's size, causing the contents to be relayed out as necessary.
如果您想限制 Stage
的大小,您需要在代码中设置 Stage
的适当属性:minWidth
、minHeight
、maxWidth
和 maxHeight
。由于您正在设置 minWidth = maxWidth
和 minHeight = maxHeight
,因此最好使用 Stage.setResizable(false)
(如 Stage
最大化,而设置 min/max 大小属性不会。虽然在我的机器上属性 do 阻止 Stage
在最大化时增长,但它会导致 Stage
跳到左上角。
由于您无权访问 Scene Builder 使用的预览 Stage
(据我所知),我认为您无法限制预览的大小。但是,您可能需要处理的一件事是预览 Stage
在关闭时打开到之前的大小。我不确定为什么这是 default/unchangeable 行为,但我 猜测 这是由于每次使用相同的 Stage
造成的。要将 Stage
调整为您喜欢的大小,您可以转到:
Preview -> Preview Size -> Preferred Size (Width x Height)
这需要显示预览,否则菜单项将被禁用。