Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Rendre un composant transparent

 set, swing, awt, JPanel, JFrame
{filelink=10252}

 
 
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.image.BufferedImage;
 
public class ComposantTransparent extends JFrame
{ 
    public ComposantTransparent()
    {
    	JFrame f = new JFrame("Exemple d'un JTextField Transparent");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        f.setSize(250, 200);
        JPanel pnl=new JPanel();
        pnl.add(new CustomJText("Je suis transparent")
        		, BorderLayout.SOUTH);        
        f.add(pnl);
        f.setVisible(true);
    }
	public static void main(String argv[]) 
    {
        Runnable showMyGUI = new Runnable() {
            public void run() {
                new ComposantTransparent();
            }
        };
        SwingUtilities.invokeLater(showMyGUI);
    }
}
 
class CustomJText extends JTextField {
 
  BufferedImage buttonImage = null;
 
  public CustomJText(String label) {
    super(label);
    setOpaque(false);
  }
 
  public void paint(Graphics g) {
    if (buttonImage == null || buttonImage.getWidth() != getWidth()
        || buttonImage.getHeight() != getHeight()) {
      buttonImage = getGraphicsConfiguration().createCompatibleImage(getWidth(), getHeight());
    }
    Graphics gButton = buttonImage.getGraphics();
    gButton.setClip(g.getClip());
    super.paint(gButton);
    Graphics2D g2d = (Graphics2D) g;
    AlphaComposite newComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f);
    g2d.setComposite(newComposite);
    g2d.drawImage(buttonImage, 0, 0, null);
  }
 
}

A Voir sur le même Sujet:

  • rendre un jpanel transparent
  • rendre un jpanel non transparent ajva
  • java rendre image transparente
  • comment rendre un jpanel transparent
  • créer un jtextfield transparent
  • faire un label transparent en swing
  • rendre un jtextfield transparant
  • rendre un jlabel transparent
  • les technique de programmation transparent en java
  • couleur transparente java swing