List of utility methods to do ImageIcon Create
ImageIcon | createImageIcon(String resourcePath) create Image Icon return new ImageIcon(Thread.currentThread().getContextClassLoader().getResource(resourcePath)); |
ImageIcon | createImageIcon(URL url) create Image Icon return (url != null) ? new ImageIcon(url) : null; |
ImageIcon | createImageIcon(URL url, String description, Integer w, Integer h) create Image Icon ImageIcon imageIcon = new ImageIcon(url, description); if (w != null && h != null) { imageIcon = new ImageIcon(imageIcon.getImage().getScaledInstance(w, h, java.awt.Image.SCALE_SMOOTH)); return imageIcon; |
JLabel | createImageIconJLabel(ClassLoader classloader, String path, String description, String text) create Image Icon J Label ImageIcon icon = createImageIcon(classloader, path, description); JLabel label = new JLabel(text, icon, JLabel.LEFT); return label; |
javax.swing.ImageIcon[] | createImageIcons(java.awt.Image... images) create Image Icons javax.swing.ImageIcon[] rv = new javax.swing.ImageIcon[images.length]; int i = 0; for (java.awt.Image image : images) { rv[i] = createImageIcon(image); i++; return rv; |
Image | getIconImage(Icon icon) get Icon Image if (icon instanceof ImageIcon) { ImageIcon imageIcon = (ImageIcon) icon; return imageIcon.getImage(); } else { Image image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) image.getGraphics(); icon.paintIcon(null, g2, 0, 0); icon = new ImageIcon(image); ... |
ImageIcon | getIconImage(String path) get Icon Image URL url = System.class.getResource(path); if (url == null) { System.err.println("Unable to load image: " + path); ImageIcon icon = new ImageIcon(url); return icon; |
ImageIcon | toImageIcon(File file, int width, int height) to Image Icon ImageIcon lImageIcon = null; BufferedImage lBufferedImage = ImageIO.read(file); if (lBufferedImage != null) { BufferedImage lBufferedImageResized = resizeImage(lBufferedImage, width, height); lImageIcon = new ImageIcon(lBufferedImageResized); return lImageIcon; |
ImageIcon | toImageIcon(Icon icon) Returns an ImageIcon based on a given Icon object. if (icon instanceof ImageIcon) { return (ImageIcon) icon; } else { return new ImageIcon(createImage(icon)); |
ImageIcon | toImageIcon(URL resource, int width, int height) to Image Icon return new ImageIcon(getScaledImage(new ImageIcon(resource).getImage(), width, height)); |