I'm using the code from this stackOverflow post, which does what I expect:
Enumeration<Object> keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get(key);
if (value instanceof FontUIResource) {
FontUIResource orig = (FontUIResource) value;
Font font = new Font(orig.getFontName(), orig.getStyle(), orig.getSize());
UIManager.put(key, new FontUIResource(font));
}
}
I tried to refactor it to the following code, which only loops through a couple of classes in javax.swing.plaf instead of the full set of components. I've tried digging around the swing API and HashTable API, but I feel like I'm still missing something obvious.
for(Object key : UIManager.getDefaults().keySet()){
Object value = UIManager.get(key);
if(value instanceof FontUIResource){
FontUIResource orig = (FontUIResource) value;
Font font = new Font(orig.getFontName(), orig.getStyle(), orig.getSize());
UIManager.put(key, new FontUIResource(font));
}
}
Any ideas why the first block of code loops over and changes all font resources, while the second only loops over a handful of items?