创建一个完全透明的JFrame

时间:2016-09-24 18:04:12

标签: java swing jframe awt transparency

我有以下课程

public class FileCopyManager extends JFrame{

   public static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
   public FileCopyManager(){
     this.setBackgroundColor(TRANSPARENT_COLOR);
   }
   public static void main(String[] args) {
        SwingUtilities.invokeLater(()->{
             try {
                UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
            }
            catch (Throwable e) {
            }
            finally{
                new FileCopyManager();
            }
         });
    }
}

但是当我尝试运行此程序时,我收到以下错误:

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
    at java.awt.Frame.setBackground(Unknown Source)

任何想法为什么会这样?

1 个答案:

答案 0 :(得分:1)

好吧,只需使用this.setUndecorated(true)