说明:java将gif设置为icon是,原本透明的地方还是透明的,先做一张半透明的图片存储为.gif
然后用它填充一个大的图 相当于半透明的背景
/**
*/
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
/*
*/
public class GTextArea extends JPanel {
JTextArea tex = null;
JLabel bg;
ImageIcon imageIcon = null;
public GTextArea() {
setLayout(null);
bg = new JLabel();
imageIcon = new ImageIcon(" .gif");
tex = new JTextArea();
bg.setIcon(imageIcon);
tex.setSize(800, 115);//
bg.setSize(800, 115);//图片要和文本一样大
tex.setOpaque(false);//文本设置透明,否则就没有效果了
bg.setLocation(0, 0);
tex.setLocation(0, 0);//位置应该一样
add(tex);//注意顺序
add(bg);
setOpaque(false);
this.setVisible(true);
}
}