Skip to main content

Help~ I cannt show .png type image in javaFx

6 replies [Last post]
molanmsn
Offline
Joined: 2008-08-26
Points: 0

hi all, I am learning JavaFx for days~ and try some sample in NetBeans6.1 with JavaFx .

this is my problem. I create a sample project named "display" by wizard .

it's a part of code like this

"var img = Image { url : "{__DIR__}/../resources/background.png" };"

I changed the url, and try to use other iamge, but the window shows nothing~

then, I opened background.png and save as another png files named background1.png

but the window still shows nothing yet~~

I had tried many image type ,jpg,gif.... the problem remains T_T

the same pic can be opend by Java2D library.

I appreciate if any one can tell me why~ thanks very much !

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
molanmsn
Offline
Joined: 2008-08-26
Points: 0

Oh, I got it ~~

thx again , the image does not exist in the class path~ I should copy it form src path

thank you michael~ u save me

molanmsn
Offline
Joined: 2008-08-26
Points: 0

thank you michael,

I donnt thinks it's the url problem ,take a look~

this is the picture when I use "Image1"

http://www.bn13.com/bbs/attachment/Mon_0808/88_55164_53e4b17943d2c44.jpg

and this is "image2", backround2.png save as backound.png by photoshop

http://www.bn13.com/bbs/attachment/Mon_0808/88_55164_267cd23dc8641b3.jpg

this is my package
http://www.bn13.com/bbs/attachment/Mon_0808/88_55164_55954db46b5967a.jpg

no console error~

what's the problem ??

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Sorry, I do not understand. What is the output, if you execute

[code]
java.lang.System.out.println("{__DIR__}../resources/background.png");
[/code]

molanmsn
Offline
Joined: 2008-08-26
Points: 0

code:java.lang.System.out.println("{__DIR__}/../resources/background.png");

out:

file:/C:/Users/wc/Documents/NetBeansProjects/Displaying/build/classes/image//../resources/background.png

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

First of all __DIR__ is a Url, pointing to the folder. If it is converted to string, it ends with a slash. The whole string you are constructing should be "{__DIR__}../resources/background.png".

Also __DIR__ might point to a different place than you expect. Print the string, to check if it is pointing to the right place. If this does not help, please post the output here, so we can have a look what might be wrong.

alexsch
Offline
Joined: 2007-07-12
Points: 0

Here is a related issue: JFXC-1805 "{__DIR__}/duke.png" path does not work in jar file
http://openjfx.java.sun.com/jira/browse/JFXC-1805