classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about createUI() method?


From: David Gilbert
Subject: Question about createUI() method?
Date: Tue, 06 Sep 2005 21:13:38 +0000
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050728)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]