Getting unexpected output from the swing program

我们两清 提交于 2020-01-06 09:03:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!