jlover2010 0 Newbie Poster

Recently i needed to override dome default values of swing properties
...
I got the answer currently needed.Details are located here

But after that i interested to find a way to have all these pairs (simply HashTable keys and values elements) to override them at the startup of applications to make custom values.

at the moment it's two days of researching (firstly documentations and source codes of jdk6u17 APIs and currently passing lots of pages of Google results) and the most and only useful things i found were two code snippets mentioned below (Both are almost same) :

public static void main(String[] args) {
        printUIManagerDefaults();
    }
  static void printUIManagerDefaults()
   {

       Object[] objs = javax.swing.UIManager.
                   getLookAndFeel().getDefaults().keySet().toArray();
       //java.util.Arrays.sort( objs );
       for( int i = 0; i < objs.length; i++ )
       {
           System.out.println(objs[i]+
              ", "+javax.swing.UIManager.getDefaults().get(objs[i]));
       }
   }

another one :

public static String windowsUI = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

    public static void main(String[] args) {
        try {

            UIDefaults def = UIManager.getDefaults();

            for (Enumeration e = def.keys(); e.hasMoreElements();) {

                String key = (String) e.nextElement();

                System.out.println(key + ": " + def.get(key));

            }

        } catch (Exception ex) {

            System.out.println(ex);

        }

    }

they will print out a lot of information though, but for example you can not find a key such OptionPane.yesButtonText or OptionPane.noButtonText or OptionPane.cancelButtonText or even swing.boldMetal that i used them as the key argument in method UIManager.put in my current application and brought an example in the thread mentioned before.

I'm really tired of searching, i couldn't find the default values from source code (i guess they made from some source code i don't have them :
This is a part of UIManager source code i think (by tracking code snippets) is exactly where the table made, but have no source code :

private static void initializeDefaultLAF(Properties swingProps)
//***find the rest of code yourself ! I dont wanna make here heavy
       HashMap lafData =
                (HashMap) AppContext.getAppContext().get("swing.lafdata");
//***again find by urself

Well
you see I'm doing my effort and will be much appreciate if any one has a useful idea and put it here

Thanks

Dani AI

Generated

— short answer: most keys you care about are supplied by the installed LookAndFeel, are localized, or are created lazily by UI delegates, so a simple dump of UIManager.getDefaults() done before the LAF is installed (or before any UI delegates have initialized) can miss them.

A reliable way to discover everything:

  • iterate the installed LAFs, set each LAF (on the EDT), force a few common UI delegates to initialize (for example construct a JOptionPane/JFrame), then enumerate UIDefaults while forcing evaluation of lazy values. This shows the final, computed values (and the real types: String, Icon, Color, Font, etc.).

Example (run on the EDT; this is intentionally different from your earlier dumps):

// Dump defaults for every installed LAF and force lazy evaluation
UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
for (UIManager.LookAndFeelInfo info : infos) {
    SwingUtilities.invokeAndWait(() -> {
        try {
            UIManager.setLookAndFeel(info.getClassName());
            // trigger some UI initialization
            new JOptionPane(); // causes OptionPane defaults to be created
            UIDefaults d = UIManager.getDefaults();
            List<String> keys = new ArrayList<>();
            for (Object k : d.keySet()) keys.add(String.valueOf(k));
            Collections.sort(keys);
            System.out.println("=== " + info.getName() + " ===");
            for (String k : keys) {
                Object v = d.get(k); // forces LazyValue evaluation
                System.out.println(k + " -> " + (v == null ? "null" : v.getClass().getName() + ": " + v));
            }
        } catch (Exception ex) { ex.printStackTrace(); }
    });
}

To override defaults at startup: set the LAF first, then apply overrides (UIManager.put) before creating any visible components. If you load overrides from a .properties file, convert values to the correct types (Color, Font, Icon) when necessary — strings are fine for text keys like OptionPane.yesButtonText. After startup, changing keys requires updating component UIs (SwingUtilities.updateComponentTreeUI).

Troubleshooting tips: confirm the LAF you inspected is actually installed; check Locale if strings are missing; use UIManager.getString(key) for localized lookups; and remember some third‑party or Synth LAFs load resources only when their UI classes are first referenced.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.