GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes Image not displayed in JLabel using Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Image not displayed in JLabel using Swing" Watch "Image not displayed in JLabel using Swing" New topic
Author

Image not displayed in JLabel using Swing

Rohit Bhagwat
Ranch Hand

Joined: Dec 19, 2004
Posts: 205
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

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Please use the getCodeBase() method.


[ December 01, 2005: Message edited by: Mathias Nilsson ]

SCJP1.4
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780

[/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

Joined: Aug 21, 2004
Posts: 367
Sorry... youre right.... just typed it not looking at an example
 
GeeCON Prague 2014
 
subject: Image not displayed in JLabel using Swing