> There's not a whole lot of help, even in the Javadoc, for knowing what
> a Renderer should look like.  

You are right, this is a weak point in the documentation.

> I...found the subtle element that, I'm
> guessing, pretty much every Renderer needs to do if it's based on a
> Component:
> 
>    @Override
>    public void setSize(int width, int height) {
>        super.setSize(width, height);
> 
>        // Since this component doesn't have a parent, it won't be validated
>        // via layout; ensure that it is valid here
>        validate();
>    }

Yes - if your renderer extends Component, you need to do this. Renderers in 
Swing have a similar requirement.

> An item renderer for ListView is a Component* that implements a couple
> extra methods, of which "render" is the interesting one -- it gets
> called when the ListView wants to layout its items or paint them.  The
> renderer's job is to modify itself to look exactly like what the
> ListView should paint in the space allocated for the item that was
> passed to render.  There are some extra arguments to render to allow
> you to customize your look according to whether the item is selected,
> highlighted etc.  The ListView all by itself is setting the background
> of each item according to that selection/highlight/whatever state, so
> the extra arguments are useful if you want to be harmonious with it,
> e.g., by making your text's foreground color be white (actually, the
> ListView's selectionColor style) when the item is selected.  That last
> bit was really non-obvious to me for some while.
> 
> (*Strictly speaking, it doesn't have to be a Component, merely
> something that implements ConstrainedVisual, but Component does
> implement ConstrainedVisual, and I expect nearly everyone would use
> some sort of Component to make the implementation tractable.)
> 
> It looks like other renderers are similar, differing mainly in the
> nature of the extra arguments to render, which depend on the
> capabilities of the container.

I don't see any reason why something like this couldn't be included in the 
documentation. Where do you think it should go?

G


Reply via email to