简体   繁体   中英

Create a completely transparent JFrame

I have the following class

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();
            }
         });
    }
}

However when I try to run this program I get the following error:

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

Any Ideas why this is happening?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM