【问题标题】:JavaFX ImageView resize in StackPaneJavaFX ImageView 在 StackPane 中调整大小
【发布时间】:2012-11-19 13:50:41
【问题描述】:

我在 StackPane 中调整 ImageView 的大小时遇到​​问题: 如果 StackPane 是根容器并且我将图像的高度和宽度绑定到 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>

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

【问题讨论】:

    标签: imageview javafx-2


    【解决方案1】:

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

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

    请参阅 JavaFX CSS 参考指南中区域规范的 background images 部分。

    制作ImageView itself resizable is an unresolved major issue。该问题链接到 code for a simple workaround - 一个可调整大小的 ImagePane 包装一个 Image 以填充可调整大小的窗格。

    【讨论】:

    • 非常感谢!)我想创建背景图像或视频,您的链接对我帮助很大。适合我的解决方法是可调整大小的窗格,其中包含 MediaView 或 ImageView。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-09
    • 2020-06-07
    • 2018-09-26
    • 1970-01-01
    • 2015-10-11
    • 2013-06-27
    相关资源
    最近更新 更多