java背景窗口程序_如何使java图形程序的窗口背景变成透明的?

阿容

3级

2009-05-16 回答

最新的jdk-6u10版本已经在进行beta测试,对于swing来说,在此版本中增加了两个重要的功能:透明窗体和不规则窗体。这两个功能使得swing也可以做出vista下的玻璃效果来了,

jdk-6u10还没有正式发布,可以在 http://download.java.net/jdk6/binaries/进行下载

publicclassTranslucentWindowextendsJFrame{

publicTranslucentWindow(){

super("透明窗体");

this.setLayout(newFlowLayout());

this.add(newJButton("按钮"));

this.add(newJCheckBox("复选按钮"));

this.add(newJRadioButton("单选按钮"));

this.add(newJProgressBar(20,100));

this.setSize(newDimension(400,300));

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstaticvoidmain(String[]args){

JFrame.setDefaultLookAndFeelDecorated(true);

SwingUtilities.invokeLater(newRunnable(){

publicvoidrun(){

Windoww=newTranslucentWindow();

w.setVisible(true);

com.sun.awt.AWTUtilities.setWindowOpacity(w,0.6f);

}

});

}

}

publicclassTranslucentWindowextendsJFrame{

publicTranslucentWindow(){

super("透明窗体");

this.setLayout(newFlowLayout());

this.add(newJButton("按钮"));

this.add(newJCheckBox("复选按钮"));

this.add(newJRadioButton("单选按钮"));

this.add(newJProgressBar(20,100));

this.setSize(newDimension(400,300));

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicstaticvoidmain(String[]args){

JFrame.setDefaultLookAndFeelDecorated(true);

SwingUtilities.invokeLater(newRunnable(){

publicvoidrun(){

Windoww=newTranslucentWindow();

w.setVisible(true);

com.sun.awt.AWTUtilities.setWindowOpacity(w,0.6f);

}

});

}

}


版权声明:本文为weixin_32349711原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。