Board index » jbuilder » How to load images into the code ...

How to load images into the code ...


2005-07-01 12:42:42 AM
jbuilder1
Hi,
I have downloaded and start to test a PrinterFrameowrk set of classes
that I found on JavaWorld.
In the PFPrintPreview class the image was loaded as:
firstPage.setIcon (new ImageIcon (getClass ().getResource
("images/FirstPage.gif")));
I added the directory "images" and put the gifs there.
But JBuilder could not find the images.
I then tried the method that worked on earlier use:
firstPage.setIcon (new ImageIcon
(printerframework.PFPrintPreview.class.getResource ("FirstPage.gif")));
How come that it didn't found them on the top code?
Dir structure
G:\jbproject\PrinterFrameWork\
G:\jbproject\PrinterFrameWork\bak
G:\jbproject\PrinterFrameWork\classes
G:\jbproject\PrinterFrameWork\src
G:\jbproject\PrinterFrameWork\src\images
G:\jbproject\PrinterFrameWork\src\printerframework
Magnus
 
 

Re:How to load images into the code ...

Magnus wrote:
Quote
Hi,

I have downloaded and start to test a PrinterFrameowrk set of classes
that I found on JavaWorld.

In the PFPrintPreview class the image was loaded as:

firstPage.setIcon (new ImageIcon (getClass ().getResource
("images/FirstPage.gif")));

I added the directory "images" and put the gifs there.

But JBuilder could not find the images.

I then tried the method that worked on earlier use:

firstPage.setIcon (new ImageIcon
(printerframework.PFPrintPreview.class.getResource
("FirstPage.gif")));

How come that it didn't found them on the top code?

Dir structure

G:\jbproject\PrinterFrameWork\
G:\jbproject\PrinterFrameWork\bak
G:\jbproject\PrinterFrameWork\classes
G:\jbproject\PrinterFrameWork\src
G:\jbproject\PrinterFrameWork\src\images
G:\jbproject\PrinterFrameWork\src\printerframework

Magnus
Resources are found relative to the class that is attempting to load
them.
If this works:
printerframework.PFPrintPreview.class.getResource("FirstPage.gif")
then that means that the images are in the same directory
(printerframework) as the class.
If you want:
printerframework.PFPrintPreview.class.getResource("images/FirstPage.gif"
)
then you need to put the images in the directory below
(printerframework/images).
--
Kevin Dean [TeamB]
Dolphin Data Development Ltd.
www.datadevelopment.com/
NEW WHITEPAPERS
Team Development with JBuilder and Borland Enterprise Server
Securing Borland Enterprise Server
www.datadevelopment.com/papers/index.html
Please see Borland's newsgroup guidelines at
info.borland.com/newsgroups/guide.html