943,808 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2106
  • Java RSS
Mar 20th, 2008
0

Image Icon displays file name text

Expand Post »
Hi, I've followed the example in my lecture notes and it doesn't work! I want to add an image to a label and then add that label to my sub north panel. I want to do this with creating a new class...I'm not sure if I need an "image loader" or to repaint it from the paint method...This code seemed to work for my lecturer:

Java Syntax (Toggle Plain Text)
  1.  
  2. logo = new ImageIcon("JavaProgram2/LogoGIF.GIF");
  3. logoLabel = new JLabel(" " + logo);
  4. logoLabel.setOpaque(true);
  5. logoLabel.setBackground(Color.white);
  6. row2.add(logoLabel); //row2 is the name of the panel

The label and logo is initialised at the beginning of my application with the Jlabel and ImageIcon var type, I have imported it, tried it without the file path with solely the file name and have tried different file types. I did look at previous posts about this but the code seemed a bit lengthly considering that I simply want to add an image.

Anyone got any ideas on how I could do this easily?
Similar Threads
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
156 posts
since Nov 2007
Mar 21st, 2008
0

Re: Image Icon displays file name text

The only thing I can think of looking at this code is: do you have an image file called LogoGIF.GIF in a subdirectory called JavaProgram2? Also, you have added the logoLabel to the panel, but you haven't provided the code where you add the logo to the panel or the panel to the rest of your GUI. Are you doing that?
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Mar 21st, 2008
0

Re: Image Icon displays file name text

lol yes I have the right name, I've looked at for a long time and row2 is a panel:

row1 = new JPanel();
row2 = new JPanel();

pNorth.add(row1, BorderLayout.NORTH);
pNorth.add(row2, BorderLayout.SOUTH);

row1.setBackground(Color.white);
row2.setBackground(Color.white);

I don't know, I've tried to resize it to a smaller size now and still doesn't work. I run out of ideas I know the panel works because it's added other buttons...
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
156 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: drawing question
Next Thread in Java Forum Timeline: Show an oval moving up til a value in an array?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC