注:這不是一個問題的答案(這是其中設置LAF)。相反,它回答了問題如何以獨立於其包名稱的方式設置LAF。如班級搬遷,簡化生活,如f.i.從com.sun *到javax.swing的Nimbus。
基本的方法是查詢UIManager安裝的LAF,循環遍歷它們直到找到匹配並設置它。 Here'r這樣的方法在SwingX實施:
/**
* Returns the class name of the installed LookAndFeel with a name
* containing the name snippet or null if none found.
*
* @param nameSnippet a snippet contained in the Laf's name
* @return the class name if installed, or null
*/
public static String getLookAndFeelClassName(String nameSnippet) {
LookAndFeelInfo[] plafs = UIManager.getInstalledLookAndFeels();
for (LookAndFeelInfo info : plafs) {
if (info.getName().contains(nameSnippet)) {
return info.getClassName();
}
}
return null;
}
使用(這裏沒有異常處理)
String className = getLookAndFeelClassName("Nimbus");
UIManager.setLookAndFeel(className);
確保Look'n'Feel配置** **前初始化框架。 – 2012-03-02 23:34:47
[編程設置外觀和感覺](http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html#programmatic) – chicout 2012-03-02 22:11:46