I saw this post: how to make Indeterminate progressbar look nicely?
That's just the opposite direction of what I want, I want to use the System (windows) look and feel, but have the nimbus progressbar.
My code so far:
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());
}
But if I compile I get the error message:
com.sun.java.swing.plaf.windows.WindowsLookAndFeel cannot be cast to > javax.swing.plaf.nimbus.NimbusLookAndFeel
where I initialize the progress bar.
If someone could explain to me what's going on and/or how to get a nimbus-looking progressbar on a system (windows) look and feel I would be so happy. I'm mainly interested in the glass-effekt.
edit: If I don't copy the progressbar defaults back, the error is gone.