標籤:
想起兩三年前,發現寫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樣式