[英]Translucent window with Windows look and feel?
I'm playing with JDK7's translucent window support and find that it doesn't work well with Windows look and feel. 我正在使用JDK7的半透明窗口支持,发现它与Windows外观不能很好地配合使用。
Here's my code: 这是我的代码:
JFrame.setDefaultLookAndFeelDecorated(true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("Translucent Window");
frame.setOpacity(0.5F);
frame.setSize(640, 360);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
This code correctly displays a translucent window. 此代码正确显示一个半透明的窗口。 However, if I set the Windows look and feel:
但是,如果我设置Windows外观:
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
an exception is thrown: 引发异常:
Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
If I disable the frame decoration with frame.setUndecorated(true)
, it works again but that is not what I want because the title bar is missing. 如果我使用
frame.setUndecorated(true)
禁用框架装饰,则它可以再次工作,但这不是我想要的,因为标题栏丢失了。 Is there any way to resolve this issue? 有什么办法解决这个问题?
See this tutorial to understand how to make a JFrame
Transparent or Translucent 请参阅本教程以了解如何使
JFrame
透明或半透明
http://blogofjavacrazy.blogspot.in/2007/03/transparent-window-in-java.html http://blogofjavacrazy.blogspot.in/2007/03/transparent-window-in-java.html
I stumbled upon a neat little hack that instead of actually being transparent, it takes a screenshot and adds that little segment as the background. 我偶然发现了一个简洁的小技巧,它实际上不是透明的,而是需要一个屏幕截图,并将该小片段添加为背景。
See this Link: 看到此链接:
http://onjava.com/pub/a/onjava/excerpt/swinghks_hack41/index.html http://onjava.com/pub/a/onjava/excerpt/swinghks_hack41/index.html
This is really stupid. 这真是愚蠢。 Under Java 6 with
AWTUtilities
, this works just fine. 在具有
AWTUtilities
Java 6 AWTUtilities
,这很好用。
You'll want to read this though. 不过,您将要阅读此内容。
Is The Java Tutorials Translucent Window example giving trouble to those playing with jdk7? Java教程“半透明窗口”示例是否给使用jdk7的用户带来麻烦?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.