Adjust font size in Swing applications global
Use this snippet to set the size of all fonts of the current Swing look and feel:
public static void setFontSizeGlobal( int size ){for ( Enumeration e = UIManager.getDefaults().keys(); e.hasMoreElements(); ){ Object key = e.nextElement(); Object value = UIManager.get( key ); if ( value instanceof Font ) { Font f = (Font) value; UIManager.put( key, new FontUIResource( f.getName(), f.getStyle(), size ) ); }}}
Can we compact the code? Not with the extended for! It is true that UIDefaults is a subtype of Hashtable but the methods entrySet() or keySet() returns an empty collection.