zoukankan      html  css  js  c++  java
  • Java:判断当前操作系统界面采用的主题是windows经典样式还是xp样式

    想起两三年前,发现写Java界面的时候,如果将当前界面的layout设为null,由于windows的不同主题界面下,标题栏的高度不一致,导致当前界面表现也不一致。

    当时就想找到一个办法先判断当前用户的主题是经典样式还是xp样式,可一直都没有找到。

    今天无意发现com.sun.java.swing.plaf.windows.StyleXP类里面的一段代码:

    /** Get the singleton instance of this class
          *
          * @return the singleton instance of this class or null if XP styles
          * are not active or if this is not Windows XP
          */
         static synchronized XPStyle getXP() {
             if (themeActive == null) {
                 Toolkit toolkit = Toolkit.getDefaultToolkit();
                 themeActive =
                     (Boolean)toolkit.getDesktopProperty("win.xpstyle.themeActive");
                 if (themeActive == null) {
                     themeActive = Boolean.FALSE;
                 }
                 if (themeActive.booleanValue()) {
                     GetPropertyAction propertyAction =
                         new GetPropertyAction("swing.noxp");
                     if (AccessController.doPrivileged(propertyAction) == null &&
                         ThemeReader.isThemed() &&
                         !(UIManager.getLookAndFeel()
                           instanceof WindowsClassicLookAndFeel)) {
    
                         xp = new XPStyle();
                     }
                 }
             }
             return xp;
         }

    原来使用 Toolkit.getDefaultToolkit().getDesktopProperty("win.xpstyle.themeActive")方法就可以返回当前的主题样式。

    2007-07-04

  • 相关阅读:
    Android_程序未处理异常的捕获与处理
    instanceof关键字
    乐优商城项目爬坑
    [LeetCode]Isomorphic Strings
    [LeetCode]Contains Duplicate II
    [LeetCode]Valid Sudoku
    [LeetCode]Valid Anagram
    [LeetCode]Contains Duplicate
    [LeetCode]Single Number
    [LeetCode]Valid Number
  • 原文地址:https://www.cnblogs.com/personnel/p/4582895.html
Copyright © 2011-2022 走看看