• Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Icons

 
VICKY
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Whenever I use image icons in my Applet, it displays everything except icons. eg. consider the code:
import java.awt.*;
import javax.swing.*;

public class JLabelDemo extends JApplet{
public void init(){
// Get Content Pane
Container contentPane = getContentPane();
// Create an icon
ImageIcon ii = new ImageIcon("france.gif");
// Create a Label
JLabel J1 = new JLabel("France", ii, JLabel.CENTER);
// Add Label to the Content Pane
contentPane.add(J1);
}
}
On execution, I just see the text France without the icon. Can somebody please tell me what is wrong with it & what else is needed to be done.
Thanks,
Vicky.

[This message has been edited by Thomas Paul (edited October 11, 2000).]
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vicky,
your code seems to be correct.
the problem may be that it is not getting the file france.gif.
make sure the file exists.and try giving the complete path.
You may wonder but there is no exception generated if the program does not find the image file in specified location.

regards
deekasha
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's probably not finding the file. Is the case correct? Is the file named France.gif? Is it in the right directory?
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Well try this sample code.. it works..
JLabel1.setIcon(imageIcon1);
add(JLabel1);
JLabel1.setBounds(12,168,384,51);
try {
imageIcon1.setImageLocation(new java.net.URL("file:///E:/Utils/Gal/astalavistalogo.jpg"));
}
catch (java.net.MalformedURLException error) { }
where imageIcon1 is an object of ImageIcon
Regds
Gautham Kasinath
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I have a problem I dont know how to insert a smiley into the JTextPane.. a smiley as an .ico or ay other image file format.
please help me with a sample code
Tanx
Gautham Kasinath
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!