Java 在拆分窗格中调整ImageView的大小
我将ImageView包装在StackPane中,该StackPane添加到SplitPane的顶部。移动拆分窗格的分隔符时,我希望ImageView调整大小以适应分配的空间,同时保留ImageView的大小比。我试图通过以下代码片段实现这一点:Java 在拆分窗格中调整ImageView的大小,java,javafx,Java,Javafx,我将ImageView包装在StackPane中,该StackPane添加到SplitPane的顶部。移动拆分窗格的分隔符时,我希望ImageView调整大小以适应分配的空间,同时保留ImageView的大小比。我试图通过以下代码片段实现这一点: Platform.runLater(() -> { image.fitHeightProperty().bind(stackpane.heightProperty()); image.fitWidthPropert
Platform.runLater(() -> {
image.fitHeightProperty().bind(stackpane.heightProperty());
image.fitWidthProperty().bind(stackpane.widthProperty());
image.setPreserveRatio(true);
});
但是,问题是ImageView只会增长,而不会收缩。我怎样才能解决这个问题?谜团已经解开!使用SplitPane的分隔器绑定似乎是解决方案。它并不完美,因为有时图像的上/下或左/右边缘都不齐平,这取决于舞台的宽度/高度,但它完成了任务
Platform.runLater(() -> {
image.fitWidthProperty().bind(splitPane.getDividers().get(0).positionProperty().multiply(splitPane.widthProperty()));
image.fitHeightProperty().bind(splitPane.getDividers().get(0).positionProperty().multiply(splitPane.heightProperty()));
imgWebCamCapturedImage.setPreserveRatio(true);
});
谜团解开了!使用SplitPane的分隔器绑定似乎是解决方案。它并不完美,因为有时图像的上/下或左/右边缘都不齐平,这取决于舞台的宽度/高度,但它完成了任务
Platform.runLater(() -> {
image.fitWidthProperty().bind(splitPane.getDividers().get(0).positionProperty().multiply(splitPane.widthProperty()));
image.fitHeightProperty().bind(splitPane.getDividers().get(0).positionProperty().multiply(splitPane.heightProperty()));
imgWebCamCapturedImage.setPreserveRatio(true);
});
这里的
root
是什么?你能创建一个吗?@James\u D对不起,根目录是一个堆栈窗格,我改变了示例以反映这一点。这里的root
是什么?你能创建一个吗?@James\u D对不起,根目录是一个stackpane,我更改了示例以反映这一点。