Mega Code Archive

 
Categories / Java Tutorial / 2D Graphics
 

Create Disabled Image from GrayFilter

import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; 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("r.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();   } }