Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Image not displayed in JLabel using Swing

 
Rohit Bhagwat
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
I have written the following code and run the program using appletviewer.
However I am not able to see the image. I can see the text but I dont see any image ? Are there any settings that need to be done ?

import java.awt.*;
import javax.swing.*;
public class JLabelDemo extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
ImageIcon li = new ImageIcon("Bluehills.jpeg");
JLabel ji = new JLabel("India",li,CENTER);
contentPane.add(ji);
}

}

Waiting for your suggestions...

Regards
Rohit.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't do applets, but I think your problem is that you are using the
ImageIcon constructor that takes a filename string. Try using the one
that takes an URL.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use the getCodeBase() method.


[ December 01, 2005: Message edited by: Mathias Nilsson ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[/qb]<hr></blockquote>

Image is abstract! Here are a few variations. Depending on whether the
image is location relative to the code or the html, you'll want to use
getCodeBase of getDocumentBase:
[ December 01, 2005: Message edited by: Jeff Albrechtsen ]
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry... youre right.... just typed it not looking at an example
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic