List of utility methods to do ImageIcon Create
ImageIcon | createImageIcon(Class clazz, String path) Returns an ImageIcon, or throws a RuntimeException if the path was invalid. URL imageUrl = clazz.getResource(path); if (imageUrl != null) { return new ImageIcon(imageUrl); throw new RuntimeException("Couldn't find file: " + path); |
ImageIcon | createImageIcon(Class clazz, String pathToImage, int sizeX, int sizeY) create Image Icon ImageIcon ret = null; if (pathToImage != null) { try { InputStream is = clazz.getResourceAsStream(pathToImage); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(buffer)) != -1) { ... |
ImageIcon | createImageIcon(Class theClass, String path, String description) Loads the image icon from a package. URL imgURL = theClass.getClass().getResource(path); if (imgURL != null) { return new ImageIcon(imgURL, description); } else { return null; |
ImageIcon | createImageIcon(Class> bezugsklasse, String path) create Image Icon final URL imgURL = bezugsklasse.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); System.err.println("Couldn't find file: " + path); return null; |
ImageIcon | createImageIcon(ClassLoader classloader, String path, String description) create Image Icon URL url = classloader.getResource(path); if (null != url) { return new ImageIcon(url); } else { final String error = "Supplied image icon resource path is unknown [" + path + "]."; throw new IllegalArgumentException(error); |
ImageIcon | createImageIcon(File f, String description) Load BufferedImage form file, scale it and converts to icon. try { BufferedImage i = ImageIO.read(f); return new ImageIcon(i.getScaledInstance(50, 50, Image.SCALE_SMOOTH)); } catch (Exception ex) { return null; |
ImageIcon | createImageIcon(final Icon icon) Creates an ImageIcon from any Icon. BufferedImage bufferedImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = bufferedImage.createGraphics(); icon.paintIcon(new JLabel(), g, 0, 0); g.dispose(); return new ImageIcon(bufferedImage); |
ImageIcon | createImageIcon(final String src) create Image Icon if (!new File(src).exists()) { return new ImageIcon(); } else { try { return new ImageIcon(ImageIO.read(new File(src))); } catch (final Throwable e) { return new ImageIcon(); |
ImageIcon | createImageIcon(java.net.URL imgURL) create Image Icon return new ImageIcon(imgURL); |
ImageIcon | createImageIcon(String iconFile) Returns an ImageIcon, or null if the iconFile is invalid. if (iconFile != null) { return new ImageIcon(iconFile); } else { System.err.println("Couldn't find file: " + iconFile); return null; |