Get default values for Swing-based user interfaceTag(s): Swing


This little class will dump to stdout the default values used by Swing. You can redirect the result to a file with
>java UIDefaults > swing.props

import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

import javax.swing.UIManager;

public class UIDefaults {
    public static void main(String[] args) {
       try {
          Set defaults = UIManager.getLookAndFeelDefaults().entrySet();
          // this TreeSet will hold the sorted properties
          TreeSet ts = new TreeSet(new Comparator() {
             public int compare(Object a, Object b) {
                Map.Entry ea = (Map.Entry) a;
                Map.Entry eb = (Map.Entry) b;
                return
                  ((String) ea.getKey()).compareTo(((String)eb.getKey()));
             }
          });
          ts.addAll(defaults);
          for (Iterator i = ts.iterator(); i.hasNext();) {
             Map.Entry entry = (Map.Entry) i.next();
             System.out.print(entry.getKey() + " = " );
             System.out.println(entry.getValue());
          }


       } catch (Exception ex) {
          ex.printStackTrace();
       }
    }
}
  • For an example on how to change a default value see this HowTo
  • To change a value for a particuliar component, see this HowTo
  • Here a sample list for JavaUIDefaults
    blog comments powered by Disqus