阶段:未根据场景调整大小
Stage: Not resizing to Scene
我在舞台上有一个场景。场景的宽度为 337.0 像素。但是,当我将它添加到舞台时,舞台的大小为 337.6 像素,由于 0.6 像素的差异,在屏幕的右边缘留下了一个白色间隙。
我尝试使用 stage.sizeToScene()
,但它不起作用。我还尝试通过 stage.setWidth(337)
手动设置舞台的宽度。不影响舞台的宽度,还是337.6.
我尝试了以下方法:stage.setWidth(337.0)
。然后当我在控制台上打印舞台宽度时,使用stage.getWidth()
,打印的值为337.0,但实际上,0.6像素的白线仍然存在。
我尝试过以下操作:
stage.hide();
stage.show();
这有效,它删除了白线,但它显示了看起来非常糟糕的 window 切换。有没有办法像上面那样切换 windows 来做同样的事情。
我们将不胜感激。
我在为我的舞台设置正确尺寸时遇到了类似的问题。
对我有帮助的是使用:
stage.setMinWidth(newActiveScene.getRoot().minWidth(-1));
stage.setMinHeight(newActiveScene.getRoot().minHeight(-1));
其中 stage
是您正在使用的舞台,newActiveScene
是舞台上的新场景。
实际上我正在使用一种方法在舞台上设置新场景,看起来像这样:
/**
* Sets a new active {@link Scene} on the stage.
*
* @param newActiveScene the new scene to show
*/
public static void setActiveScene(Scene newActiveScene) {
stage.setScene(newActiveScene);
stage.setMinWidth(newActiveScene.getRoot().minWidth(-1));
stage.setMinHeight(newActiveScene.getRoot().minHeight(-1));
}
其中 stage
是使用的舞台。这假设 stage.show()
已经被调用一次(例如在初始化阶段时)。
根据@wollsi 的建议,我想对他的代码进行一些编辑。这对我很有效:
public void setActiveScene(Scene newActiveScene) {
stage.setScene(newActiveScene);
stage.setWidth(newActiveScene.getRoot().minWidth(-1));
stage.setHeight(newActiveScene.getRoot().minHeight(-1));
}
我在舞台上有一个场景。场景的宽度为 337.0 像素。但是,当我将它添加到舞台时,舞台的大小为 337.6 像素,由于 0.6 像素的差异,在屏幕的右边缘留下了一个白色间隙。
我尝试使用 stage.sizeToScene()
,但它不起作用。我还尝试通过 stage.setWidth(337)
手动设置舞台的宽度。不影响舞台的宽度,还是337.6.
我尝试了以下方法:stage.setWidth(337.0)
。然后当我在控制台上打印舞台宽度时,使用stage.getWidth()
,打印的值为337.0,但实际上,0.6像素的白线仍然存在。
我尝试过以下操作:
stage.hide();
stage.show();
这有效,它删除了白线,但它显示了看起来非常糟糕的 window 切换。有没有办法像上面那样切换 windows 来做同样的事情。
我们将不胜感激。
我在为我的舞台设置正确尺寸时遇到了类似的问题。
对我有帮助的是使用:
stage.setMinWidth(newActiveScene.getRoot().minWidth(-1));
stage.setMinHeight(newActiveScene.getRoot().minHeight(-1));
其中 stage
是您正在使用的舞台,newActiveScene
是舞台上的新场景。
实际上我正在使用一种方法在舞台上设置新场景,看起来像这样:
/**
* Sets a new active {@link Scene} on the stage.
*
* @param newActiveScene the new scene to show
*/
public static void setActiveScene(Scene newActiveScene) {
stage.setScene(newActiveScene);
stage.setMinWidth(newActiveScene.getRoot().minWidth(-1));
stage.setMinHeight(newActiveScene.getRoot().minHeight(-1));
}
其中 stage
是使用的舞台。这假设 stage.show()
已经被调用一次(例如在初始化阶段时)。
根据@wollsi 的建议,我想对他的代码进行一些编辑。这对我很有效:
public void setActiveScene(Scene newActiveScene) {
stage.setScene(newActiveScene);
stage.setWidth(newActiveScene.getRoot().minWidth(-1));
stage.setHeight(newActiveScene.getRoot().minHeight(-1));
}