Hi,

A quick question about Swing:

A lot of the createUI() methods in the look and feel code are implemented with a HashMap to retain references to the UI delegates that are created. For example:

  public static ComponentUI createUI(JComponent component)
  {
    if (instances == null)
      instances = new HashMap();

    Object o = instances.get(component);
    MetalComboBoxUI instance;
    if (o == null)
      {
        instance = new MetalComboBoxUI();
        instances.put(component, instance);
      }
    else
      instance = (MetalComboBoxUI) o;

    return instance;
  }

I was wondering if anyone can explain the purpose of retaining the instance for each component? (As opposed to just returning a new instance for each call). As I understand it, the createUI() method will only be called once for each component each time the look and feel is changed. So I don't see the need for retaining the instances in the HashMap. Any pointers?

Regards,

Dave


_______________________________________________
Classpath mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath

Reply via email to