Java by API/javax.swing/ImageIcon
ImageIcon: getImage()
<source lang="java">
import java.awt.Image; import javax.swing.GrayFilter; import javax.swing.Icon; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class Main {
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ImageIcon icon = new ImageIcon("yourFile.gif"); Image normalImage = icon.getImage(); Image grayImage = GrayFilter.createDisabledImage(normalImage); Icon warningIcon = new ImageIcon(grayImage); JLabel warningLabel = new JLabel(warningIcon); JLabel label3 = new JLabel("Warning", icon, JLabel.CENTER); frame.add(warningLabel,"Center"); frame.add(label3,"South"); frame.setSize(300, 200); frame.setVisible(true); }
}
</source>
ImageIcon: setDescription(String description)
<source lang="java">
import javax.swing.ImageIcon; public class Main {
public static void main(String[] argv) throws Exception { ImageIcon icon = new ImageIcon("image.gif"); icon.setDescription("Description of Image"); }
}
</source>
new ImageIcon(String filename)
<source lang="java">
import java.awt.Image; import javax.swing.ImageIcon; public class Main {
public static void main(String[] a) { ImageIcon imageIcon = new ImageIcon("yourFile.gif"); Image image = imageIcon.getImage(); }
}
</source>