gpt4 book ai didi

java - 在 SplitPane 中调整 ImageView 的大小

转载 作者:太空宇宙 更新时间:2023-11-04 10:58:33 24 4
gpt4 key购买 nike

我有一个包含在 StackPane 中的 ImageView,该 ImageView 添加到 SplitPane 的顶部。当我移动 SplitPane 的分隔线时,我希望调整 ImageView 的大小以适合分配的空间,同时保留 ImageView 的大小比例。我尝试使用以下代码片段来实现此目的:

Platform.runLater(() -> {
image.fitHeightProperty().bind(stackpane.heightProperty());
image.fitWidthProperty().bind(stackpane.widthProperty());
image.setPreserveRatio(true);
});

然而,这样做的问题是 ImageView 只会增长,而不会缩小。我该如何解决这个问题?

最佳答案

谜团解开了!使用 SplitPane 的分隔线绑定(bind)似乎是解决方案。它并不完美,因为有时图像不与顶部/底部或左/右边缘齐平,具体取决于舞台的宽度/高度,但它可以完成工作。

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);
});

关于java - 在 SplitPane 中调整 ImageView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47140754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com