如何检测显示器是否处于高对比度模式? [英] How do I detect if a display is in High Contrast mode?

查看:281
本文介绍了如何检测显示器是否处于高对比度模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试公司已建立的Swing应用程序的可访问性问题。在我的PC上启用高对比度模式后,此应用程序的某些部分会正确呈现(黑底白字),而某些部分会呈现不正确(黑底白字)。

I'm testing my company's established Swing application for accessibility issues. With high contrast mode enabled on my PC certain parts of this application are rendered properly (white-on-black) and some incorrectly (black-on-white).

正确的位是JIDE之类的本地组件(JButton,JLabel和whatnot)和第三方组件。不正确的位是自定义组件,并且是内部开发的渲染器,没有考虑高对比度模式。

The bits that are correct are the native components (JButton, JLabel and whatnot) and third party components from the likes of JIDE. The incorrect bits are custom components and renderers developed in-house without consideration for high-contrast mode.

很明显,可以检测到何时启用了高对比度模式。我该怎么做?

Clearly it's possible to detect when high-contrast mode is enabled. How do I do this?

推荐答案

原来为此在Java 1.4.1中添加了win.highContrast.on属性。

Turns out the win.highContrast.on property was added in Java 1.4.1 for this purpose.

public static void main(String[] args) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Boolean highContrast = (Boolean)toolkit.getDesktopProperty( "win.highContrast.on" );
}

仅在Windows上有效(因此 win。 前缀)。在Linux和Mac上, highContrast 将为空。最安全的做法是先进行平台检查,或者对 highContrast 进行空检查。

This only works on Windows (hence the win. prefix). On linux and Mac highContrast will be null. It'll be safest to do a platform check first, or a nullcheck on highContrast.

这篇关于如何检测显示器是否处于高对比度模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆