[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about createUI() method?
From: |
Roman Kennke |
Subject: |
Re: Question about createUI() method? |
Date: |
Wed, 07 Sep 2005 12:17:13 +0200 |
Am Dienstag, den 06.09.2005, 21:13 +0000 schrieb David Gilbert:
> 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?
That was introduced by me. Honestly I don't remember myself why I found
this important. I think I might have been mislead of the API docs in
ComponentUI.createUI(): 'If the UI delegate is stateful, then it should
return a new instance per component.'
I think it would be ok to change this to simply return a new instance on
each call without storing them in the hashtables.
Best regards,
Roman