These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ImageIcon class.
return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR); } java.net.URL handURL = JComponentDragHandler.class.getResource(location); assert handURL != null : "Can not find hand cursor image " + cursorName; ImageIcon handicon = new ImageIcon(handURL); Dimension cursize = Toolkit.getDefaultToolkit().getBestCursorSize(handicon.getIconWidth(), handicon.getIconHeight()); BufferedImage buffImg = GraphicsManager.gc.createCompatibleImage( cursize.width, cursize.height, Transparency.TRANSLUCENT); Graphics2D buffImgG2 = (Graphics2D) buffImg.getGraphics(); Point cpoint = new Point(cursize.width / 2 - handicon.getIconWidth() / 2, cursize.height / 2 - handicon.getIconHeight() / 2); buffImgG2.drawImage(handicon.getImage(), cpoint.x, cpoint.y, null); return Toolkit.getDefaultToolkit().createCustomCursor(buffImg, new Point(cpoint.x + 5, cpoint.y), cursorName); }
private Font versionTextFont = null; public FreeplaneSplashModern(final JFrame frame) { super(frame); splashResource = ResourceController.getResourceController().getResource("/images/Freeplane_splash.png"); splashImage = new ImageIcon(splashResource); setBackground(new Color(0x57, 0xbf, 0x5e)); final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension labelSize = new Dimension(splashImage.getIconWidth(), splashImage.getIconHeight()); setLocation(screenSize.width / 2 - (labelSize.width / 2), screenSize.height / 2 - (labelSize.height / 2)); setSize(labelSize); RootPane rootPane = new RootPane(); rootPane.setSize(labelSize); setRootPane(rootPane); } private void createVersionTextFont() { if(versionTextFont != null){ return; }
String imageName = key + (style + 1) + ".gif"; Image image = (Image) imageMap.get(imageName); if (image == null) { System.err.println("name=" + imageName); URL imageLoc = getClass().getResource("resources/" + imageName); image = new ImageIcon(imageLoc).getImage(); imageMap.put(imageName, image); } return image; } }
Image base = imgCache.get(DEFAULT_DIMENSION); if (base == null) throw new AssertionError(); int width = dim.width; int height = dim.height; ImageIcon icon = new ImageIcon(base); if (width == -1) { width = Math.max(1, icon.getIconWidth() * height / icon.getIconHeight()); } else if (height == -1) { height = Math.max(1, icon.getIconHeight() * width / icon.getIconWidth()); } Image i = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); img.getGraphics().drawImage(i, 0, 0, null); imgCache.put(dim, img); return new ImageIcon(img); } } /**
Toolkit defaultToolkit = Toolkit.getDefaultToolkit(); URL path = ActionW.class.getResource("/icon/cursor/" + filename); //$NON-NLS-1$ if (path == null) { return null; } ImageIcon icon = new ImageIcon(path); Dimension bestCursorSize = defaultToolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight()); Point hotSpot = new Point((hotSpotX * bestCursorSize.width) / icon.getIconWidth(), (hotSpotY * bestCursorSize.height) / icon.getIconHeight()); return defaultToolkit.createCustomCursor(icon.getImage(), hotSpot, cursorName); } }
if(leftImage == null) return rightImage; if(rightImage == null) return leftImage; // Check the cache to see if there's a set of combination icons with // this as the leftmost image. Map<Object, ImageIcon> combos = _icons.get(leftImage); // If we've never cached anything for this leftImage before, create // a map of (_icons[left])[right] -> combined icon. if(combos == null) { ImageIcon new_icon = appendIcons(leftImage, rightImage); combos = new HashMap<Object, ImageIcon>(); combos.put(rightImage, new_icon); _icons.put(leftImage, combos); return new_icon; } // We know we've got a combination map, so get the combination for the // rightside icon. ImageIcon old_icon = combos.get(rightImage); // If we didn't have a combination for that pair, build it.
private void chooseImage() throws MalformedURLException { JFileChooser fileChooser = new JFileChooser(); fileChooser.showOpenDialog(this); Path file = fileChooser.getSelectedFile().toPath(); Icon imageIcon = new ImageIcon(file.toUri().toURL()); setSize(imageIcon.getIconWidth(), imageIcon.getIconHeight() + 100); imageLabel.setIcon(imageIcon); String decodeText = getDecodeText(file); textArea.setText(decodeText); } private static String getDecodeText(Path file) { BufferedImage image; try { image = ImageReader.readImage(file.toUri()); } catch (IOException ioe) { return ioe.toString(); } LuminanceSource source = new BufferedImageLuminanceSource(image);
x += (bounds.width - w) / 2; y += (bounds.height - h) / 2; g.drawImage(getImage()/*scaledImage*/, x, y, w, h, getImageObserver()); int oiw = (int) (ICON_STATIC.getIconWidth() * s); int oih = (int) (ICON_STATIC.getIconHeight() * s); if ((m_flags & FLAG_CONSTRUCTOR) > 0) { g.drawImage(ICON_CONSTRUCTOR.getImage(), x + oiw, y + oih, oiw, oih, getImageObserver()); } if ((m_flags & FLAG_STATIC) > 0) { g.drawImage(ICON_STATIC.getImage(), x, y, oiw, oih, getImageObserver()); } if ((m_flags & FLAG_FINAL) > 0) { g.drawImage(ICON_FINAL.getImage(), x + oiw, y, oiw, oih, getImageObserver()); }
} // due to an issue with ImageIO and mixed signed code // we are now using good oldfashioned ImageIcon to load // images and the paint it on top of a new BufferedImage Image img = new ImageIcon(url).getImage(); BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics g = bufferedImage.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); return bufferedImage; } }