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:

  • java rendre un panel transparent
  • enlever un composant swing
  • rendre un composant transparent
  • composant translucide
  • rendre texte bouton java transparent
  • composant awt transparent
  • animation des composants java
  • java proxy transparent port d'entrée et de sortie
  • rendre un objet transparent java
  • java rendre une liste transparente