2012-02-20 88 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()方法改變了外觀和感覺雨雲,創建按鈕,然後改變了外觀和回想起調用該方法時的情況。