<Swing Dev> 6179357: Generics: JList: ListCellRenderer & prototypeCellValue
Alexander Potochkin
Alexander.Potochkin at Sun.COM
Tue Mar 3 18:27:12 UTC 2009
Hello Florian
I must confess that I don't think it is desirable
to generify every class in Swing, so #1 looks good for me
:-)
Two generic parameters add to much of typing, in my opinion
Could you please provide a complete example of a JList
with a custom ListCellRenderer that proves that renderer should be
generified
By the way the more examples the better,
another one which promotes JList generifying
would also help to promote this idea for Swing team members
Thanks
alexp
> So, 2 votes for option 3), which is a reasonable one, I think.
>
> Pavel? Anyone else?
>
> -Florian
>
> Am Sonntag, 22. Februar 2009 schrieb Erik Lundqvist:
>> Hi,
>> ListCellRenderer should absolutely be generic which rules out option 1 :)
>> I cannot remember ever using the prototypeCellValue so a bit worried about
>> saying too much about how people are using it, but it does not seem
>> unreasonable that it should be of the same type so I would go for Option 3
>> as well which seems the simpler and most common use case.
>>
>> //erik
>>
>> 2009/2/21 Florian Brunner <fbrunnerlist at gmx.ch>
>>
>>> Hi,
>>>
>>> I think adding generics to the ListCellRenderer could also be useful. The
>>> problem is that in JList
>>> the same cell renderer is used for the items as for the
>>> prototypeCellValue - and the
>>> prototypeCellValue doesn't necessarily have be of the same type as the
>>> items!
>>>
>>> So I think we have 3 options:
>>>
>>> 1) Don't provide a generic cell renderer/ allow only Object as parameter
>>> for the cell renderer in
>>> JList.
>>>
>>> 2) Add a second generic parameter. Eg. something like:
>>> class JList <E, P super E>{ ... }
>>>
>>> and use P for the prototypeCellValue property as well as for the cell
>>> renderer.
>>>
>>> 3) Require prototypeCellValue to be of type E. In the probably rare
>>> cases, where this is a problem
>>> one can still specify a common base class of the items and the
>>> prototypeCellValue as the generic
>>> parameter or use a raw type JList.
>>>
>>>
>>>
>>> I think it would be a pity not to provide a generic cell renderer (1) and
>>> think 2) is inconvenient
>>> and confusing, since in my experiences prototypeCellValue is only used
>>> rarely.
>>>
>>> So I'm voting for 3). For which option do you vote? For which reason?
>>>
>>>
>>>
>>> Note I also propose to use:
>>>
>>> ListCellRenderer<? super E> cellRenderer
>>>
>>> rather than
>>>
>>> ListCellRenderer<E> cellRenderer
>>>
>>> in JList. This would make it more flexible. Do you agree? (It's actually
>>> the first time, I think, I
>>> use 'super' with generics myself, but I think this is a good use case of
>>> it. So any comments are
>>> welcome. ;-) )
>>>
>>> -Florian
>
>
More information about the swing-dev
mailing list