Re: JComboBox cell renderer doesn't render the top item
- From: usenet@xxxxxxx (Christian Kaufhold)
- Date: Fri, 25 Nov 2005 02:04:49 +0100
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
.
- References:
- JComboBox cell renderer doesn't render the top item
- From: hiwa
- Re: JComboBox cell renderer doesn't render the top item
- From: Kari Ikonen
- JComboBox cell renderer doesn't render the top item
- Prev by Date: Re: JTextPane problem
- Next by Date: keep open JComboBox drop-down list
- Previous by thread: Re: JComboBox cell renderer doesn't render the top item
- Next by thread: Graphics2D problem
- Index(es):
Relevant Pages
|