Java Swing Tutorial - Java ImageIcon(String filename) Constructor








Syntax

ImageIcon(String filename) constructor from ImageIcon has the following syntax.

@ConstructorProperties(value ="description")public ImageIcon(String filename)

Example

In the following code shows how to use ImageIcon.ImageIcon(String filename) constructor.

import java.awt.Image;
//from  w w w .  jav a  2  s.co m
import javax.swing.ImageIcon;

public class Main {

  public static void main(String[] a) {
    ImageIcon imageIcon = new ImageIcon("yourFile.gif");
    Image image = imageIcon.getImage();

  }

}