是否可以在java 7中使用半透明窗口,包括标题栏? [英] Is it possible to have a translucent windows in java 7 including a title bar?
问题描述
与此问题相关:
Java教程半透明窗口示例给使用jdk7的人带来麻烦吗?
使用jdk1.6.0_26我似乎能够申请半透明到JFrame,但jre7不是这样:
with jdk1.6.0_26 I seem to be able to apply translucency to a JFrame, but not so with jre7:
NativeException:java.awt.IllegalComponentStateException:框架被装饰
NativeException: java.awt.IllegalComponentStateException: The frame is decorated
ex(jruby脚本java,工作jdk1.6但不是jdk7):
ex (jruby scripting java, works jdk1.6 not with jdk7 though):
require 'java'
class MouseDraw
def self.go
java_import 'javax.swing.JFrame'
java_import 'com.sun.awt.AWTUtilities'
f = JFrame.new
AWTUtilities.set_window_opacity(f, 0.5)
f.set_size 200,200
f.show
end
end
MouseDraw.go
所以我的问题是是否可以进行转换jdk7中的ucent标题栏(我想要一个透明窗口,我正在创建可拖动/可调整大小)
So my question is "is it possible to have a translucent title bar in jdk7" (I would like a transparent window I'm creating to be draggable/resizable)
推荐答案
Java 7介绍了 Window.setOpacity()
执行Java 6中非官方类 AWTUtilities
的操作。
Java 7 introduced Window.setOpacity()
to do what the unofficial class AWTUtilities
did in Java 6.
不幸的是,它记录不适用于装饰窗口:
Unfortunately it's documented not to work with decorated windows:
为了设置不透明度,必须满足以下条件值小于
1.0f
:
-
TRANSLUCENT
底层系统必须支持半透明 - 窗口必须未修饰(参见
Frame.setUndecorated(boolean)
和Dialog.setUndecorated(boolean)
) - 窗口不得处于全屏模式(参见
GraphicsDevice.setFullScreenWindow(Window)
)
- The
TRANSLUCENT
translucency must be supported by the underlying system - The window must be undecorated (see
Frame.setUndecorated(boolean)
andDialog.setUndecorated(boolean)
) - The window must not be in full-screen mode (see
GraphicsDevice.setFullScreenWindow(Window)
)
(强调我的)
这篇关于是否可以在java 7中使用半透明窗口,包括标题栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!