JavaFX图像加载错误 [英] JavaFX image loading error

查看:792
本文介绍了JavaFX图像加载错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在JavaFX中实现一个非常简单的Raspberry Pi接口。我使用基于.fxml的布局和样式我的项目与CSS。我的问题是,尽管应用程序在我的主计算机(从eclipse运行)完美地工作,它不工作在树莓上,当我尝试运行导出的jar在主机上。

I'm trying to implement a very simple interface to Raspberry Pi in JavaFX. I'm using an .fxml based layout and styling my items with css. My problem is despite the app works perfectly in my main computer(running from eclipse) it's not working on Raspberry nor when I try to run the exported jar on main computer.

这是我如何皮肤我的按钮。 Ofcourse resources / images文件夹在我的建筑路径。

This is how I skinned my button. Ofcourse resources/images folder is in my building path. The buttons has the color what I described in css, but the image is not loading.

.imageButton1 {
-fx-background-color: blue;
-fx-graphic: url('file:resources/images/temperature.png');}


$ b b

它给我以下错误:

It give me the following error:


警告:加载图片时出错:file:resources / images / temperature.png


WARNING: Error loading image: file:resources/images/temperature.png

我将我的项目上传到 dropbox

推荐答案

项目的问题在resources文件夹中。找不到源文件夹之外。

The problem with your project is in the resources folder. Being outside the source folder is not found.

这是我的工作方式:

创建一个JavaFX项目,并移动源文件夹中的资源文件夹。所以这是源包:

Created a JavaFX project in NetBeans, and moved the resource folder inside the source one. So this is Source Packages:

-Source Packages
    +me.noip.blase
    +me.noip.blase.view
    +resources.images

,然后将所有引用从 file:至/:

and then changed all references from file: to "/":

primaryStage.getIcons().add(new Image("/resources/images/icon.png"));

和css档案:

.imageButton1 {
        -fx-background-color: blue;
        -fx-graphic: url('/resources/images/temperature.png');
}
.imageButton2 {
        -fx-graphic: url('/resources/images/gear.png');
        -fx-background-color: red;
}
.imageButton3 {
        -fx-graphic: url('/resources/images/power.png');
        -fx-background-color: black;
}

.imageButton4 {
        -fx-graphic: url('/resources/images/diagram.png');
        -fx-background-color: green;
}

现在,在桌面和Raspberry Pi上都可以正常工作。

Now it works fine in both desktop and Raspberry Pi.

这篇关于JavaFX图像加载错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆