问题
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.
回答1:
SetUndecorated is called on a frame to remove The title bar/maximize button/ etc. Here is a good example: http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html#shaped
来源:https://stackoverflow.com/questions/11865197/getting-unexpected-output-from-the-swing-program