Swing ImageIcon Class :
package com.c4learn.swing;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class JImageIconDemo {
private JFrame mainFrame;
private JPanel mainPanel;
public JImageIconDemo() {
mainFrame = new JFrame("Java Swing Examples");
mainFrame.setSize(400, 400);
mainFrame.setLayout(new GridLayout(3, 1));
mainPanel = new JPanel();
mainPanel.setLayout(new FlowLayout());
mainFrame.add(mainPanel);
mainFrame.setVisible(true);
}
public static void main(String[] args) {
JImageIconDemo demo = new JImageIconDemo();
demo.showLabelDemo();
}
private void showLabelDemo() {
ImageIcon icon = new ImageIcon("images/java.jpg");
JLabel label = new JLabel("Java",icon,JLabel.RIGHT);
mainPanel.add(label);
mainFrame.setVisible(true);
}
}
Output :
