如何用Java制作全窗航空玻璃?
我正在尝试编写一个小型应用程序,但我希望整个窗口都是玻璃的,上面有按钮和标签。在Java中可以做到这一点吗?
I am trying to program a small application but I would like the entire window to be glass with buttons and labels on top of it. Is it possible to do this within Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设 Java SWT 及其朋友没有对 Windows Aero 技术的内置支持,您将必须通过 JNI 调用本机 API。您需要调用的本机 API 是
此本机 API 可在 Windows Vista 和 Windows 7 中的 DWMAPI.dll 本机库中找到,并且为 记录在 MSDN 上。
网上有很多关于如何调用此函数的文档。例如,这里有一篇关于在 C# 中执行此操作的文章。这应该可以帮助你开始。
Assuming Java SWT and friends do not have built-in support for Windows Aero technology, you're going to have to call a native API via JNI. The native API you'll need to call is
This native API is found in the DWMAPI.dll native library in Windows Vista and Windows 7, and is documented on MSDN.
There's lot of documentation on the web about how to call this function. For example, here's an article on doing this in C#. That should get you started.
当然,此功能高度依赖于平台(在本例中为 Windows),因此需要 JNI。
假设您已经检查过玻璃窗是否已启用。步骤为:
步骤 1-3 是用 C 编写的。让
HWND hwnd
为要玻璃化的窗口的句柄,并让COLORREF color
为颜色(越不寻常越好):第 4 步是简单的 Java,类似于
其中
color
是之前选择的颜色的 Java 版本。Of course this feature is highly platform-dependent (Windows, in this case) so JNI is needed.
Let's assume you have already checked that glass windows are enabled. The steps are:
Steps 1-3 are written in C. Let
HWND hwnd
a handle to the window you want to glassify and letCOLORREF color
a color (the more unusual, the best):Step 4 is simple Java, something like
where
color
is the Java version of the color chosen before.唔。我认为所有 Java GUI 都必须直接或间接地在
Window
中显示,这是一个重量级组件。不确定是否可以使其透明/半透明。尝试构建一个 JFrame 并将其背景颜色设置为
new Color(255, 255, 255, 20)
左右,其中 20 是 Alpha。这要么让它变得基本上透明——要么就不起作用。Hmm. I think that all Java GUI must be displayed, directly or indirectly, in a
Window
, and that's a heavyweight component. Not sure if you can make it transparent/translucent.Try building a JFrame and setting its background color to
new Color(255, 255, 255, 20)
or so, where 20 is the alpha. That should either make it mostly transparent - or it won't work.