0

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.

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');}

It give me the following error:

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

I uploaded my project into dropbox

blase
  • 67
  • 1
  • 8

2 Answers2

2

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

This is how I made it work:

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

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

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

and the css file:

.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;
}

Now it works fine in both desktop and Raspberry Pi.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • I tried what you suggested and maybe i did something wrong or i cant reproduce what you think. I changed the references to / and tried to make the same structure as yours. Here's a picture about my current [structure](https://dl.dropboxusercontent.com/u/20634377/icons/structure.PNG) But i still got the Error loading image error messages – blase Feb 25 '15 at 23:13
  • Why is there an empty `resources` folder? Shouldn't that one have the image files? – José Pereda Feb 25 '15 at 23:15
  • It seems a strange way that eclipse show the structure of the project, but that isnt really empty, because if i delete that, my src/resources/images folder disappear too. – blase Feb 25 '15 at 23:26
  • I don't use Eclipse, so I can't tell. What I did was just having a regular package with images. Maybe when you put it outside src, it's not added to the jar. – José Pereda Feb 25 '15 at 23:29
  • Can you upload your project somewhere? Maybe I can find out from that. (since I'm trying to load images with / instead of file: , the pictures arent loading when I lunch the app in the IDE) – blase Feb 25 '15 at 23:36
0

I will accept your solution as an answer, I tried importing to NetBeans and it worked, but I cannot reproduce that under Eclipse. Meanwhile I found another question here and followed that solution and it works(I dont know how I didn't find that before, I massively googled for a day)

I will leave this here if anyone else searchs for this.

Thank you very much for your time and help :)

Community
  • 1
  • 1
blase
  • 67
  • 1
  • 8
  • Thanks for posting back, it looks like the solution you mention is also inserting the resources within the source folder (you can call it "resources" or not). – José Pereda Feb 26 '15 at 01:42