【问题标题】:In JavaFX 2.1 button image is not shown在 JavaFX 2.1 中,按钮图像未显示
【发布时间】:2012-05-28 06:50:04
【问题描述】:

JavaFX 2.1:

我的带有图像的按钮在 JavaFX 2.0 中运行良好。升级到JavaFX 2.1,图像消失了。

代码如下:

Button aButton = new Button("Test");
String iconPath = "/com/abc/res/toolbar/Help.gif";
Image aIcon = new Image(
    getClass().getResourceAsStream(iconPath), 18, 18, false, false);
aButton.setGraphic(new ImageView(aIcon));

这适用于 JavaFX 2.0。它在 JavaFX 2.1 下不起作用。为了使图形显示出来,我必须删除 re-size 功能。

Image aIcon = new Image(getClass().getResourceAsStream(iconPath));

有什么建议吗?

【问题讨论】:

    标签: javafx-2


    【解决方案1】:

    未显示调整大小图像的按钮图形似乎是一种回归 - 要修复它,请使用示例代码和示例图像向 http://javafx-jira.kenai.com 提交错误。

    作为一种解决方法,在构造函数中加载图像而不调整其大小,并通过imageView.fitWidth()imageView.fitHeight()ImageView 中调整加载图像的大小。

    【讨论】:

    • imageView.fitWidth() 有效。 aImageView.setFitHeight(18); aImageView.setFitWidth(18);---谢谢
    猜你喜欢
    • 2014-05-07
    • 2020-10-01
    • 2021-10-14
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多