问下,JAVA中的容器,例如JFrame,JInternalFrame,JPanel之类的可以设置透明吗?可以上个例子程序我参考下吗,谢谢!

解决方案 »

  1.   

    setVisible(false)把组件隐藏了 这算是透明的一种么
      

  2.   


    import java.awt.*;
    import java.awt.geom.Ellipse2D;import javax.swing.*;public class TranslucentShapedWindow extends JFrame {
    public TranslucentShapedWindow() {
    super("Test translucent and oval-shaped window");
    this.setLayout(new FlowLayout());
    this.add(new JButton("test"));
    this.add(new JCheckBox("test"));
    this.add(new JRadioButton("test"));
    this.add(new JProgressBar(0, 100)); this.setSize(new Dimension(400, 300));
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
    Window w = new TranslucentShapedWindow();
    w.setVisible(true);
    com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.5f);
    com.sun.awt.AWTUtilities
    .setWindowShape(w, new Ellipse2D.Double(0, 0, w
    .getWidth(), w.getHeight()));
    }
    });
    }}需要JDK1.6.10以上版本
      

  3.   

    com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.5f);这个0.5f是设置透明度的 给2#注释一下 呵呵
      

  4.   

    问下
    com.sun.awt.AWTUtilities这又是第三方包中的类吗?有源码吗?提供下下载地址,谢谢!
      

  5.   

    知道了,晕了 要更新JDK了.
      

  6.   

    搞定了,真是太强大了.
    等出JDK7了,听说这个会被整合到java包下面吧.
    又学了点东西,谢谢啰!!!