首页 > 编程语言 > 详细

Java:判断当前操作系统界面采用的主题是windows经典样式还是xp样式

时间:2015-06-17 13:16:45      阅读:160      评论:0      收藏:0      [点我收藏+]

想起两三年前,发现写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

Java:判断当前操作系统界面采用的主题是windows经典样式还是xp样式

原文:http://www.cnblogs.com/personnel/p/4582895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!