GrayFilter: Create a disabled version of an Image : Image ImageIcon « Swing « Java Tutorial






GrayFilter: Create a disabled version of an Image
import java.awt.Image;

import javax.swing.GrayFilter;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class CreateDiabledVersionOfanImage {

  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    ImageIcon icon = new ImageIcon("yourFile.gif");

    Image normalImage = icon.getImage();
    Image grayImage = GrayFilter.createDisabledImage(normalImage);
    Icon warningIcon = new ImageIcon(grayImage);
    JLabel warningLabel = new JLabel(warningIcon);

    JLabel label3 = new JLabel("Warning", icon, JLabel.CENTER);

    frame.add(warningLabel,"Center");
    frame.add(label3,"South");

    frame.setSize(300, 200);
    frame.setVisible(true);
  }

}








14.117.Image ImageIcon
14.117.1.Getting Image object from ImageIcon object
14.117.2.GrayFilter: Create a disabled version of an ImageGrayFilter: Create a disabled version of an Image
14.117.3.use the image proxy. Images are only loaded when you press on a tab