简体   繁体   中英

Getting unexpected output from the swing program

In the following code why i'm getting an invisible window?What does setUndecorated() do and where it is used for.

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;


public class UsingJLayer {

UsingJLayer()
{
    JFrame jfrm=new JFrame("Picasa Viewer");
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Dimension dim=Toolkit.getDefaultToolkit().getScreenSize();
    jfrm.setSize(dim);
    jfrm.setUndecorated(true);
    jfrm.setBackground(new Color(0,100,0,0));


    jfrm.setVisible(true);

}
public static void main(String[] args) {
    //JFrame.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(new Runnable(){public void run(){new UsingJLayer();}});

}

}

Secondly if i comment out jfrm.setUndecorated(true) and instead use JFrame.setDefaultLookAndFeelDecorated(true); then i get a translucent window as expected. So,what is setUndecorated() and JFrame.setDefaultLookAndFeelDecorated(true); .I have to use one of them as otherwise an exception is thrown.

在框架上调用SetUndecorated以删除标题栏/最大化按钮/等。这是一个很好的示例: http : //docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html#shaped

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