• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically setting an ImageIcon's image file name

 
Angelo Edades
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am working on a project and have come across a stumbling block when it comes to getting an image in a JLabel to appear at all.

For now lets us assume the following:

a image file called a.gif is in the root directory of the project.

I have the following declared on my class called Aclass.



Now when the user clicks a button, actionPerformed checks the source and then asks a method called getImage (from Bclass) to return the string which is the file name as "a.gif".

Bclass.getImage queries the database and uses the appropriate column to return the file name for a given key. So far I have managed to get this bit right.

Back to Aclass, I manage to assign a.gif to imgProductStr and when I do a System.out.println(imgProductStr); within the logic it does print out a.gif which is correct.

A few lines down I use the following code to assign the file name to an instance of ImageIcon.



I am completely stumped.

All I can think of is that it is returning it as a.gif when really it should be going in to the instance of ImageIcon as "a.gif" with quotation marks but this has not worked either.



Any help / pointers would be appreciated.

 
Angelo Edades
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any moderators able to delete this thread?

I have finally found out the answer after testing a dozen of combinations. I had to creating a new instance of ImageIcon when I receive the image file name.
 
Rob Spoor
Sheriff
Pie
Posts: 20671
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We don't delete threads. Your solution may help someone who encounters the same problem and stumbles upon this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic