无法检测到 Windows 经典主题处于活动状态
我正在调用 UIManager.getSystemLookAndFeelClassName()。 并获得 WindowsLookAndFeel 结果,即使将当前主题设置为 WindowsClassicLookAndFeel 也是如此。但我期望 WindowsClassicLookAndFeel。 问题是如何检测 Windows 经典主题现在处于活动状态
I am calling UIManager.getSystemLookAndFeelClassName().
And get as result WindowsLookAndFeel, even when setting current theme to WindowsClassicLookAndFeel. But I expect WindowsClassicLookAndFeel.
Question is how can I detect that windows classic theme is now active
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UIManager.getLookAndFeel ()
返回当前安装的 LaF。getSystemLookAndFeel()
返回看起来像当前系统主题的外观,例如 Windows 上的 WindowsLookAndFeel Linux 上的 GTKLookAndFeel Solaris 上的 MOtifLookAndFeel 等。UIManager.getLookAndFeel()
returns currently installed LaF.getSystemLookAndFeel()
returns look and feel that would look as a current system's theme, e.g. WindowsLookAndFeel on windows GTKLookAndFeel on Linux MOtifLookAndFeel on Solaris etc.我不太确定你在问什么。
如果您询问 SWING 当前使用的是哪个主题/外观和感觉,请尝试
UIManager.getSystemLookAndFeelClassName()。
如果您想找出 Windows 正在使用哪个主题 - 我不知道。可能不太容易发现这一点。
编辑: 一个快速的 hack 可能是(除了使用 JNA/JNA 直接查询正在使用的主题的某些 Windows API 之外)创建一个新的 JFrame,将其放置在某个区域,捕获一小部分该边框并将其与边框样本进行比较(您需要事先创建并随代码一起发送,以便能够以编程方式比较刚刚拍摄的屏幕捕获位和您发送的所有边框图像)
I'm not quite sure what you are asking.
If you are asking which theme/look and feel SWING is currently using, try
UIManager.getSystemLookAndFeelClassName().
If you are trying to find out which theme Windows is using - I don't know. Probably not quite easy to find that out.
Edit: A quick hack might be (apart from using JNA/JNA to query some Windows API directly which theme is being used) would be creating a new JFrame, place it in some area, capture a small part of that border and compare it with samples of borders (which you need to create beforehand and ship with your code, as to be able to programmatically compare the just-taken-screen-capture-bit and all border-images you ship)
看来你是专门报名来问这个问题的,现在我是专门报名来回答这个问题的!我在谷歌上搜索了一些完全不同的东西,但我很感兴趣并做了一些实验,这就是我的发现:
您对
WindowsClassicLookAndFeel
的看法是正确的。此类扩展了WindowsLookAndFeel
,但不会覆盖任何内容,并且即使在 Windows Classic 处于活动状态时也似乎根本没有使用。因此,我查看了WindowsLookAndFeel
的代码,发现了一些有趣的内部代码,它们引用了包私有类XPStyle
。该类似乎是一个单例,并且 getter 方法getXP()
仅在“XP”主题处于活动状态时返回其实例:有趣的是,代码会检查
WindowsClassicLookAndFeel
> 再次,但我们知道它不再使用(也许它已更改)...但最好的部分是检查桌面属性win.xpstyle.themeActive
从代码中提取它,我做了以下测试:您可以将此类导入到您的程序中,并在设置 Look&Feel 后随时调用
isWindowsClassicLAF()
方法。我还给出了一个示例,说明如何在运行时侦听主题的更改。这是在 XP 上尝试和测试的。如果用户从一个 XP 主题更改为另一个 XP 主题,则侦听器不会触发,但如果用户从一个主题更改为经典主题,则侦听器会触发,反之亦然。
我希望这有帮助!
It looks like you signed up specifically to ask this question, and now I'm signing up specifically to answer it! I was Googling for something completely different but I was intrigued and did some experimenting, and here's what I found:
You're right about the
WindowsClassicLookAndFeel
. This class extendsWindowsLookAndFeel
but doesn't override anything, and doesn't appear to be used at all, even when Windows Classic is active. So, I looked into the code ofWindowsLookAndFeel
and found some interesting internal code that references the package-private classXPStyle
. This class appears to be a singleton and the getter method,getXP()
, only returns its instance if the 'XP' theme is active:Interestingly, the code checks for the
WindowsClassicLookAndFeel
again but we know that this is no longer used (perhaps it's changed)... But the best part is the check for the desktop propertywin.xpstyle.themeActive
Extracting this from the code, I made the following test:You can import this class into your program and call the
isWindowsClassicLAF()
method after setting your Look&Feel at any point. I've also given an example of how you can listen out for changes to the theme at run-time.This is tried and tested on XP. If the user changes from one XP theme to another, the listener doesn't fire, but if the user changes from a theme to Classic, or vice-versa, it will.
I hope that helps!