• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Image Icons

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic