JLabelImage.jpg
************************************************************************
COMPLETE SOURCE CODE FOR : JLabelImage.java
************************************************************************
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.awt.Toolkit;
public class JLabelImage
{
public static void main(String[]args)
{
//Create image icon from your image file
//You must change location for your image file
//My image file is locate at : C:\Documents and Settings\evergreen\Desktop
ImageIcon ii=new ImageIcon("C:\\Documents and Settings\\evergreen\\Desktop\\JLabelImage.jpg");
//Create a label with your image file
JLabel label=new JLabel(ii);
//Create a window using JFrame with title ( Put image on JLabel )
JFrame frame=new JFrame("Put image on JLabel");
//Add created label into JFrame
frame.add(label);
//Set default close operation for JFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Set JFrame size
frame.setSize(400,400);
//Make JFrame visible. So we can see it.
frame.setVisible(true);
}
}
************************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************************