Swing/NimbusLookAndFeel のバックアップの現在との差分(No.2)
- category: swing folder: NimbusLookAndFeel title: NimbusLookAndFeelを使用する tags: [LookAndFeel, NimbusLookAndFeel, UIManager] author: aterai pubdate: 2013-07-22T01:35:03+09:00 description: LookAndFeel一覧からNimbusLookAndFeelを名前で検索取得して使用します。 image:
概要
LookAndFeel
一覧からNimbusLookAndFeel
を名前で検索取得して使用します。Nimbus Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)などのサンプルから引用しています。
概要
LookAndFeel
一覧からNimbusLookAndFeel
を名前で検索取得して使用します。Nimbus Look and Feel (The Java™ Tutorials > Creating a GUI With JFC/Swing > Modifying the Look and Feel)などのサンプルから引用しています。
Screenshot
Advertisement
サンプルコード
サンプルコード
#spandel
try{
#spanend
for(UIManager.LookAndFeelInfo laf: UIManager.getInstalledLookAndFeels()) {
if("Nimbus".equals(laf.getName())) {
UIManager.setLookAndFeel(laf.getClassName());
}
}
#spandel
}catch(Exception e) {
#spanend
//e.printStackTrace();
#spanadd
try {
#spanend
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
// // 以下はJDK 1.7.0 以前を考慮する必要がある場合の指定方法
// for (UIManager.LookAndFeelInfo laf: UIManager.getInstalledLookAndFeels()) {
// if ("Nimbus".equals(laf.getName())) {
// UIManager.setLookAndFeel(laf.getClassName());
// }
// }
#spanadd
} catch (ClassNotFoundException | InstantiationException
#spanend
| IllegalAccessException | UnsupportedLookAndFeelException ex) {
ex.printStackTrace();
}
View in GitHub: Java, Kotlin解説
JDK 1.7.0
でNimbusLookAndFeel
のパッケージが移動されて完全クラス名が変更されたので、NimbusLookAndFeel
のインスタンスを生成して設定するのではなく、一旦UIManager.getInstalledLookAndFeels()
で全LookAndFeelInfo
を取得し、名前がNimbus
となっているLookAndFeel
を検索してからその完全クラス名を取得しています。
解説
JDK 1.7.0
でNimbusLookAndFeel
のパッケージが移動されて完全クラス名が変更されたのでJDK 1.6.0_10
との互換性を考慮する場合は注意が必要です。
JDK 1.6.0_10
:com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
-
JDK 1.7.0
:javax.swing.plaf.nimbus.NimbusLookAndFeel
- 一旦
UIManager.getInstalledLookAndFeels()
で全LookAndFeelInfo
を取得し名前がNimbus
となっているLookAndFeel
を検索してその完全クラス名を取得
- 一旦
-
JDK 1.7.0
以降:javax.swing.plaf.nimbus.NimbusLookAndFeel
- 完全クラス名から
NimbusLookAndFeel
のインスタンスを生成して設定
- 完全クラス名から