2015-11-13 18 views
0

我看到這個帖子:how to make Indeterminate progressbar look nicely?雨雲進度條的外觀和感覺

這只是我想要什麼,我想使用的系統(Windows)的外觀和感覺相反的方向,但有靈氣進度。

我迄今爲止代碼:

private void setLookAndFeel(){ 

    // set nimbus look&feel 
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 
     if ("Nimbus".equals(info.getName())) { 
      try { 
       UIManager.setLookAndFeel(info.getClassName()); 
      } catch (ClassNotFoundException | InstantiationException 
        | IllegalAccessException 
        | UnsupportedLookAndFeelException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      break; 
     } 
    } 

    // copy progress bar defaults 
    HashMap<Object, Object> progressDefaults = new HashMap<>(); 
    for(Map.Entry<Object, Object> entry : UIManager.getDefaults().entrySet()){ 
     if(entry.getKey().getClass() == String.class && ((String)entry.getKey()).startsWith("ProgressBar")){ 
      progressDefaults.put(entry.getKey(), entry.getValue()); 
     } 
    } 

    // set system look&feel 
    try { 
     UIManager.setLookAndFeel(
       UIManager.getSystemLookAndFeelClassName()); 
     SwingUtilities.updateComponentTreeUI(this); 
    } catch (Exception e) { 
     JOptionPane.showMessageDialog(null, "Couldn't use system look and feel: " + e); 
    } 

    // copy back progress bar defaults 
    for(Map.Entry<Object, Object> entry : progressDefaults.entrySet()){ 
     System.out.println(entry.getKey().toString() + ": " + entry.getValue()); 
     UIManager.put(entry.getKey(), entry.getValue()); //getDefaults(). 
    } 
    System.out.println("lookAndFeel " + UIManager.getLookAndFeel()); 
} 

但如果我編譯我得到的錯誤信息:

com.sun.java.swing.plaf.windows.WindowsLookAndFeel不能轉換爲> javax.swing.plaf.nimbus.NimbusLookAndFeel

其中我初始化進度條。

如果有人可以向我解釋發生了什麼和/或如何獲得一個系統(窗口)外觀上看起來像光環的進度條我會很高興。 我主要對glass-effekt感興趣。

編輯:如果我不復制進度條的默認值,錯誤消失了。

+0

在您顯示的代碼中沒有ProgressBar或強制轉換。 – FredK

+0

那麼,引發錯誤的行是 pb = new JProgressBar(0,100); – murkr

回答

0

我不知道問題是什麼,但解決方案如下: 將方法分成兩部分(直接在「//複製進度欄默認值」之前)。 然後調用設置靈氣看起來&感覺的方法,然後初始化類變量(以及進度條)的方法。第三,調用所有從「//複製進度條默認值」開始的新方法。 (該方法將複製進度條的默認值從光環看起來&的感覺,設置系統的外觀和感覺,然後粘貼進度條的默認值)。

此行只是作爲解決方法添加到AWEFUL captcha廢話的東西。