create swing Image Icon - Java Swing

Java examples for Swing:Icon

Description

create swing Image Icon

Demo Code


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JComponent;

public class Main{
    public static void main(String[] argv) throws Exception{
        String path = "java2s.com";
        System.out.println(createImageIcon(path));
    }//ww w .j  a  va2 s .  co m
    public static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = ArchiveUtil.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL, path);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
}

Related Tutorials