Re: JComboBox cell renderer doesn't render the top item



Hello!

Kari Ikonen <mr.kari.ikonen@xxxxxxxxx> wrote:

> hiwa wrote:
>
>> Below is an SSCCE for the problem. The renderer renders
>> item text in the drop down list in italic font. But it doesn't render
>> the top item of the box in italic. What could be the solution. T.I.A.
>
> Problem is the fact that BasicComboBoxUI will do following for the returned
> list cell renderer:
>
> c.setFont(comboBox.getFont());
>
> i.e. it enforces font of the combobox into one defined for combobox.
>
>
> One workaround for this is this:
>
> private static final class ItalicRenderer
> extends DefaultListCellRenderer
> {
> private final JComboBox mComboBox;
>
> public ItalicRenderer(final JComboBox pComboBox) {
> mComboBox = pComboBox;
> }


public void setFont(Font value)
{
}

protected void setFont_really(Font value)
{
super.setFont(value);
}

and always use setFont_really (alternatively
set a flag in getListCellRendererComponent so that setFont works).
The same must really be done for foreground/background, as has been
discussed before.

> ...
> public Component getListCellRendererComponent(
> ...






> mComboBox.setFont(newFont);

<shudder>


Christian
.