how to make Indeterminate progressbar look nicely?

2019-08-07 07:57发布

I'm using nimbus lookAndFill

UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

and my indeterminate JProgressBar looks like that:

http://img15.imageshack.us/img15/9470/uglyprogress.jpg

can i make it looks better?

2条回答
混吃等死
2楼-- · 2019-08-07 08:38

There's an easier solution. You can just copy the progress bar UI defaults before setting the nimbus look-and-feel and then set them back after. You then get Nimbus look and feel but without its progress bar styling.

// 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 nimbus
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

// copy back progress bar defaults
for(Map.Entry<Object, Object> entry : progressDefaults.entrySet()){
    UIManager.getDefaults().put(entry.getKey(), entry.getValue());
}
查看更多
登录 后发表回答