<Swing Dev> 6179357: Generics: JList: Constructors & Model

Pavel Porvatov Pavel.Porvatov at Sun.COM
Tue Feb 3 16:38:19 UTC 2009


Hi Florian,

> ----------------------------------------
> 
> public JList(ListModel dataModel)
> 
> {
> 
> if (dataModel == null) {
> 
> throw new IllegalArgumentException("dataModel must be non null");
> 
> }
> 
> // Register with the ToolTipManager so that tooltips from the
> 
> // renderer show through.
> 
> ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
> 
> toolTipManager.registerComponent(this);
> 
> layoutOrientation = VERTICAL;
> 
> this.dataModel = dataModel;
> 
> selectionModel = createSelectionModel();
> 
> setAutoscrolls(true);
> 
> setOpaque(true);
> 
> updateUI();
> 
> }
> 
> --->
> 
> public JList(ListModel<E> dataModel)
> 
> {
> 
> if (dataModel == null) {
> 
> throw new IllegalArgumentException("dataModel must be non null");
> 
> }
> 
> // Register with the ToolTipManager so that tooltips from the
> 
> // renderer show through.
> 
> ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
> 
> toolTipManager.registerComponent(this);
> 
> layoutOrientation = VERTICAL;
> 
> this.dataModel = dataModel;
> 
> selectionModel = createSelectionModel();
> 
> setAutoscrolls(true);
> 
> setOpaque(true);
> 
> updateUI();
> 
> }
> 
> We could define the signature also like this:
> 
> public JList(ListModel<? extends E> dataModel)
> 
> but then we would have to define the dataModel-field also with:
> 
> private ListModel<? extends E> dataModel
> 
> as well as the model-property. I don't think this would be a good idea 
> and thus define the signature as:
> 
> public JList(ListModel<E> dataModel)
> 
> What do you think?
Why do you think that "private ListModel<? extends E> dataModel" is not 
a very good idea?

Regards, Pavel



More information about the swing-dev mailing list