Create Disabled Image from GrayFilter in Java

Description

The following code shows how to create Disabled Image from GrayFilter.

Example


import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/* ww  w  .j  a v  a 2  s .c  o m*/
import javax.swing.GrayFilter;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Main extends JFrame {
  public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    ImageIcon icon = new ImageIcon("a.gif");

    JButton b1 = new JButton("Regular", icon);
    p.add(b1);

    Image image = GrayFilter.createDisabledImage(icon.getImage());
    JButton b2 = new JButton("GrayFilter", new ImageIcon(image));
    p.add(b2);

    getContentPane().add(p);

    pack();
    setVisible(true);
  }

  public static void main(String arg[]) {
    new Main();
  }
}

The code above generates the following result.

Create Disabled Image from GrayFilter in Java




















Home »
  Java Tutorial »
    Graphics »




Animation
BufferedImage
Color
Font
Gradient
Graphics Settings
Image
Mouse Draw
Print
Shape
Text
Transform