【问题标题】:JavaFX: scale ImageView to table column widthJavaFX:将 ImageView 缩放到表列宽度
【发布时间】:2015-12-16 22:03:07
【问题描述】:

我在表格列中显示图像。缩放我使用的图像

    image.fitWidthProperty().bind(col.widthProperty().subtract(40));

但如果图像宽度大于列宽,我需要一个仅缩放的解决方案。在其他情况下,我将使用原始图像宽度。

我怎么写?

【问题讨论】:

    标签: javafx imageview width html-table scale


    【解决方案1】:

    图像加载后,您可以通过在Image(而不是ImageView)上调用getWidth() 来获取其宽度。

    那你就可以了

    image.fitWidthProperty().bind(
        Bindings.when(col.widthProperty().lessThan(imageWidth + 40))
                .then(col.widthProperty().subtract(40))
                .otherwise(imageWidth));
    

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-27
      相关资源
      最近更新 更多