How do I detect if a display is in High Contrast mode?

浪子不回头ぞ 提交于 2019-12-01 09:16:45

问题


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).

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?


回答1:


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" );
}

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.




回答2:


Extract from this link : http://www.section508.gov/IRSCourse/mod02/printJava.html

"Windows software can check for the high contrast setting by calling the SystemParametersInfo function with the SPI_GETHIGHCONTRAST value. Applications should query and support this value during initialization and when processing WM_COLORCHANGE messages."

This is to access via the Win32 API : http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx (Not fully sure how, though, not really good in that field, hope someone can complete)




回答3:


Did you try

Toolkit.getDefaultToolkit().getColorModel()


来源:https://stackoverflow.com/questions/1062711/how-do-i-detect-if-a-display-is-in-high-contrast-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!