List of usage examples for javax.swing ImageIcon ImageIcon
public ImageIcon(byte[] imageData)
From source file:Main.java
public static ImageIcon getImageIcon(String resource) { URL imageURL = ClassLoader.getSystemResource(resource); ImageIcon image = new ImageIcon(imageURL); return image; }
From source file:Main.java
public static JLabel toSwingImage(final BufferedImage image) { JLabel label = new JLabel(new ImageIcon(image)); label.setAlignmentX(JComponent.CENTER_ALIGNMENT); return label; }
From source file:Main.java
public static final ImageIcon loadIcon(Class pRootClass, String strPath) { URL imgURL = pRootClass.getResource(strPath); if (imgURL != null) return new ImageIcon(imgURL); else/*from w w w. j a v a 2s .c o m*/ return null; }
From source file:Main.java
/** * * @param filename nom de l'image./*from w ww . j a v a 2 s . com*/ * @return l'image. */ public static ImageIcon lireImageIcon(final String filename) { URL url = Main.class.getResource("images/" + filename); return new ImageIcon(Toolkit.getDefaultToolkit().getImage(url)); }
From source file:TabSample.java
static void add(JTabbedPane tabbedPane, String label, int mnemonic) { int count = tabbedPane.getTabCount(); JButton button = new JButton(label); tabbedPane.addTab(label, new ImageIcon("yourFile.gif"), button, label); tabbedPane.setMnemonicAt(count, mnemonic); }
From source file:Main.java
/** * @param label/*from w w w .ja v a2 s. co m*/ * @param iconFileName * @return createb JButton used in toolbar */ public static JButton createToolbarButton(String label, String iconFileName) { JButton button = new JButton(new ImageIcon(iconFileName)); button.setFocusPainted(false); button.setMargin(new Insets(0, 0, 0, 0)); button.setToolTipText(label); button.setActionCommand(label); return button; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/*from w w w.j a v a 2 s . c om*/ // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities()); } catch (Exception e) { // The system does not have a screen } return bimage; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }/* www. ja v a2 s. c o m*/ // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200); } catch (HeadlessException e) { // The system does not have a screen } return bimage; }
From source file:Main.java
/** * If icon is an instance of {@link ImageIcon}, * returns an icon scaled to the height of the component. * Else return the icon given.//from w w w.j ava2s. c om */ public static Icon scaleToHeight(JComponent c, Icon icon) { Icon sizedIcon = icon; if (icon instanceof ImageIcon) { int h = c.getPreferredSize().height - c.getInsets().top - c.getInsets().bottom; sizedIcon = new ImageIcon(((ImageIcon) icon).getImage().getScaledInstance(-1, h, Image.SCALE_SMOOTH)); } return sizedIcon; }
From source file:Main.java
public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; }//w w w . ja v a2 s . c o m // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); // Create a buffered image with a format that's compatible with the screen BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); VolatileImage vbimage = gc.createCompatibleVolatileImage(200, 200, gc.getImageCapabilities(), Transparency.BITMASK); } catch (Exception e) { // The system does not have a screen } return bimage; }