2012-02-20 6 views

答えて

1

あり、より良い方法かもしれませんが、以下のユーティリティクラスは、あなたのために働く必要があります。

import javax.swing.JButton; 
import javax.swing.LookAndFeel; 
import javax.swing.UIManager; 
import javax.swing.UIManager.LookAndFeelInfo; 


public class NimbusButton { 
    private static LookAndFeel nimbus; 

    public static JButton generateNimbusButton() { 
     try { 
      LookAndFeel current = UIManager.getLookAndFeel(); //capture the current look and feel 

      if (nimbus == null) { //only initialize Nimbus once 
       for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 
        if ("Nimbus".equals(info.getName())) { 
         UIManager.setLookAndFeel(info.getClassName()); 
         break; 
        } 
       } 
       nimbus = UIManager.getLookAndFeel(); 
      } 
      else 
       UIManager.setLookAndFeel(nimbus); //set look and feel to nimbus 
      JButton button = new JButton(); //create the button 
      UIManager.setLookAndFeel(current); //return the look and feel to its original state 
      return button; 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
      return new JButton(); 
     } 
    } 
} 

generateNimbusButton()メソッドは、外観を変更し、ニンバスに感じて、ボタンを作成し、その後、外観を変更し、メソッドが呼び出されたときの状態に戻ります。

関連する問題