gpt4 book ai didi

imageview - JavaFX ImageView 在 StackPane 中调整大小

转载 作者:行者123 更新时间:2023-12-04 04:10:51 27 4
gpt4 key购买 nike

我在调整 StackPane 中的 ImageView 大小时遇到​​了问题:如果 StackPane 是根容器并且我将图像的高度和宽度绑定(bind)到 StackPane,那么一切都很好。

<StackPane id="StackPane" fx:id="stack" prefHeight="400.0" prefWidth="600.0" style="-fx-background-color: lightgreen;" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml" fx:controller="javafxapplication8.FXMLController">
<children>
<ImageView fx:id="image" fitHeight="100.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true" />
</children>
<stylesheets>
<URL value="@fxml.css" />
</stylesheets>
</StackPane>

但是如果我将这样的堆栈 Pane 放置在例如网格中,则图像不会正确调整大小。正如我所读,ImageView 是不可调整大小的问题。有什么方法可以让它调整大小吗?或者您能否提供一些有关如何调整 ImageView 大小的建议?

最佳答案

听起来您正在尝试为 StackPane 创建背景图像。在这种情况下,通过 CSS 应用图像可能是比 ImageView 更好的使用方式。

.stack-pane {
-fx-background-image: url("flower.png");
-fx-background-size: cover;
}

参见 background images JavaFX CSS 引用指南中的区域规范部分。

制作ImageView itself resizable is an unresolved major issue .问题链接到 code for a simple workaround - 可调整大小的 ImagePane 包装图像以填充可调整大小的 Pane 。

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

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