似乎可以设置大量的UI属性
UIManager.put("key", value);
Run Code Online (Sandbox Code Playgroud)
是否有可以设置的所有键的某个列表?
我正在使用此stackOverflow帖子中的代码,它完成了我的期望:
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));
}
}
Run Code Online (Sandbox Code Playgroud)
我试图将它重构为以下代码,它只循环遍历javax.swing.plaf中的几个类而不是完整的组件集.我试过挖掘swing API和HashTable API,但我觉得我仍然缺少一些明显的东西.
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));
}
}
Run Code Online (Sandbox Code Playgroud)
任何想法为什么第一个代码块循环并更改所有字体资源,而第二个代码只循环几个项目?