Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java in netbeans --> images don't appear

Reply
Thread Tools

java in netbeans --> images don't appear

 
 
SV
Guest
Posts: n/a
 
      10-20-2004
Hello,

I just installed Netbeans, and everything works fine except one thing:

When I try to run something graphic that contains images, the images never
appear.
Allthough when I run the same program in DOS, everything works fine! What I
am doing wrong?

I am sure that the exact same code works fine in DOS, and that the image is
really in the correct folder.


 
Reply With Quote
 
 
 
 
Tim Ward
Guest
Posts: n/a
 
      10-20-2004

>
> I just installed Netbeans, and everything works fine except one thing:
>
> When I try to run something graphic that contains images, the images never
> appear.
> Allthough when I run the same program in DOS, everything works fine! What

I
> am doing wrong?
>
> I am sure that the exact same code works fine in DOS, and that the image

is
> really in the correct folder.


If the method you use to locate the image depends on any concept of "current
directory" be aware that NetBeans tends to set this to something completely
useless and unexpected for no obviously good reason. (Applications *should*
*not* mess with the current directory *ever* - it belongs to the user, and
only the user should get to change it. For some reason the NetBeans people
won't acknowledge that this is a bug.)

The solution is to choose a different method of locating the image file, one
that doesn't depend on the "current directory" method. Of course, you're
likely to have chosen some relative path means of navigation so as to avoid
the even worse use of absolute paths ...

Look up the various bits of

Toolkit.getDefaultToolkit().getImage( MyApplication.class.getResource(
"myicon.gif" ) )

and related stuff until you manage to come up with a similarly
incomprehensible magic incantation that does what you want. I think the
above works because "MyApplication.class" and "myicon.gif" are in the same
directory, but the details of this gibberish are so horrendous that I
deliberately forgot them as soon as I got the code working.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk
 

Last edited by Ian; 10-04-2009 at 04:54 PM..
Reply With Quote
 
 
 
 
SV
Guest
Posts: n/a
 
      10-20-2004
The image file and the java file are in the same directory, so I just do
cp.add(new JLabel(new ImageIcon("image.gif")));
I don't want to use different methodes etc. for that because it 's a project
for school so it has to look like it 's not written especially for NetBeans
....
So I 'll either have to find a solution, or look for a different IDE
Right now I 'm editing the code in NetBeans, and testing in DOS, but that 's
a shame because all NetBeans' functions for compiling and running are not
used ...

> > When I try to run something graphic that contains images, the images

never
> > appear.
>>


> Look up the various bits of Toolkit.getDefaultToolkit().getImage(

MyApplication.class.getResource(
> "myicon.gif" ) )
>
> and related stuff until you manage to come up with a similarly
> incomprehensible magic incantation that does what you want.>



 
Reply With Quote
 
Tim Ward
Guest
Posts: n/a
 
      10-20-2004

> The image file and the java file are in the same directory, so I just do
> cp.add(new JLabel(new ImageIcon("image.gif")));
> I don't want to use different methodes etc. for that because it 's a

project
> for school so it has to look like it 's not written especially for

NetBeans

No, the type of solution I outlined is *not* specific to NetBeans, it's how
you are *supposed* to do this sort of thing "properly". Your own code would
quite possible fail if you were in a different current directory when you
ran it from the command line completely independently of NetBeans - try it.

--
Tim Ward
Brett Ward Limited - www.brettward.co.uk
 

Last edited by Ian; 10-04-2009 at 04:54 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NetBeans - JDialog does not appear as a choice Dom Java 2 11-28-2006 01:54 PM
Eclipse vs. Netbeans. Netbeans is winning me over almost at first glance. Thomas G. Marshall Java 2 10-16-2006 02:54 AM
[NETBEANS] [EVALUATION] - E12 - The NetBeans Open Source Lie Ilias Lazaridis Java 0 12-12-2004 02:41 PM
Building a GUI using NetBeans platform (not Netbeans IDE !) Pimousse Java 2 04-21-2004 07:22 AM
Web page images appear in wrong places, duplicated and stretched Mike Computer Support 7 02-20-2004 08:38 AM



Advertisments