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

posted @ 2015-06-17 12:22  personnel  阅读(693)  评论(0编辑  收藏  举报
友情链接:图片批量处理工具 gif动态图制作工具 制作电子相册 图片排版工具 制作淘宝主图视频 MKScript 鼠标键盘自动化脚本语言