Example usage for javax.swing JComponent createImage

List of usage examples for javax.swing JComponent createImage

Introduction

In this page you can find the example usage for javax.swing JComponent createImage.

Prototype

public Image createImage(ImageProducer producer) 

Source Link

Document

Creates an image from the specified image producer.

Usage

From source file:RGBGrayFilter.java

/**
 * Returns an icon with a disabled appearance. This method is used
 * to generate a disabled icon when one has not been specified.
 *
 * @param component the component that will display the icon, may be null.
 * @param icon the icon to generate disabled icon from.
 * @return disabled icon, or null if a suitable icon can not be generated.
 *///from   w w  w  .j  av  a  2s  .c o m
public static Icon getDisabledIcon(JComponent component, Icon icon) {
    if ((icon == null) || (component == null) || (icon.getIconWidth() == 0) || (icon.getIconHeight() == 0)) {
        return null;
    }
    Image img;
    if (icon instanceof ImageIcon) {
        img = ((ImageIcon) icon).getImage();
    } else {
        img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
        icon.paintIcon(component, img.getGraphics(), 0, 0);
    }

    ImageProducer producer = new FilteredImageSource(img.getSource(), new RGBGrayFilter());

    return new ImageIcon(component.createImage(producer));
}

From source file:Main.java

@Override
public void paint(Graphics g, JComponent c) {
    JLayer jlayer = (JLayer) c;
    JProgressBar progress = (JProgressBar) jlayer.getView();
    int w = progress.getSize().width;
    int h = progress.getSize().height;

    if (bi == null || w != prevw || h != prevh) {
        bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    }//w  w w .ja  v  a2s .  co m
    prevw = w;
    prevh = h;

    Graphics2D g2 = bi.createGraphics();
    super.paint(g2, c);
    g2.dispose();

    Image image = c.createImage(new FilteredImageSource(bi.getSource(), new RedGreenChannelSwapFilter()));
    g.drawImage(image, 0, 0, c);
}