<Swing Dev> 6179357: Generics: JList: ListCellRenderer & prototypeCellValue
Alexander Potochkin
Alexander.Potochkin at Sun.COM
Thu Mar 5 17:41:13 UTC 2009
Hello Florian
Thank you for the constructive examples!
I looked at the usage of prototypeCellValue property,
following the JList.updateFixedCellSize() method
I found this code in the
DefaultListCellRenderer.getListCellRendererComponent():
if (value instanceof Icon) {
setIcon((Icon)value);
setText("");
}
else {
setIcon(null);
setText((value == null) ? "" : value.toString());
}
It means that value always can be an icon,
so we need to do something about that
I also think that shouldn't generify prototypeCellValue,
since it doesn't give as any visible advantage,
moreover some programmers may use an object of a special type
that toString() method returns something meaningful for prototypeCellValue
Thanks
alexp
> Here is a second sample.
>
> It's not really a real-world sample, but should be useful to show that also JList of other "value"
> types than String, such as Integer, Long and Short, can profit from generics.
>
> It also shows why JList should specify
> ListCellRenderer<? super E> cellRenderer
>
> rather than
>
> ListCellRenderer<E> cellRenderer
>
> (Here: a common Number-cell renderer is used.)
>
> -Florian
>
> Am Dienstag, 3. März 2009 schrieb Alexander Potochkin:
>> Hello Tom
>>
>> It's nice to see you here
>>
>>>> Could you please provide a complete example of a JList
>>>> with a custom ListCellRenderer that proves that renderer should be
>>>> generified
>>> I bet if you used NetBeans to find implementations of ListCellRenderer
>>> even within the JDK most useful implementations would cast the value
>>> argument.
>> anyway, it is always better to have a fixed set of examples to discuss
>>
>>> (I prefer option 3, btw.)
>> Thanks
>> alexp
>>
>>> Tom Hawtin
>
>
More information about the swing-dev
mailing list