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



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 Component getListCellRendererComponent(
...
mComboBox.setFont(newFont);
return this;
}
}


--
KI -- http://kari.world.dy.fi
.



Relevant Pages

  • Re: JComboBox cell renderer doesnt render the top item
    ... The renderer renders ... >> item text in the drop down list in italic font. ... > i.e. it enforces font of the combobox into one defined for combobox. ... > private static final class ItalicRenderer ...
    (comp.lang.java.gui)
  • Re: Editor / Renderer: data flow
    ... When I set an editor and a renderer to a jtable, ... My editor return an Object from getCellEditorValue method. ... I ask this cause I've set an editor with a comboBox to a jxtreetable ... comboBox disappear and the cell remains as before... ...
    (comp.lang.java.gui)
  • Re: Seltsame =?ISO-8859-1?Q?Gr=F6sse_einer_JComboBox?=
    ... Als Model dient ein DefaultComboBoxModel und für die Anzeige benutze ich einen Renderer. ... Das Problem ist, das die Combobox völlig zusammengefallen dargestellt wird, sofern kein Landesteil in der Locale vorhanden ist. ... Oder ist das Leerzeichen kein "ordentliches" Zeichen, aufgrund dessen man die Höhe der Combobox berechnen kann? ... Ein Leerstring ist ein String der Länge 0, ...
    (de.comp.lang.java)