JComboBox cell renderer doesn't render the top item
- From: "hiwa" <HGA03630@xxxxxxxxxxx>
- Date: 24 Nov 2005 02:06:34 -0800
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.
---------------
import javax.swing.*;
import java.awt.*;
public class CellRender{
JFrame frame;
Container con;
JComboBox jcb;
String[] items
= {"fudai", "rubi", "zeneha", "suupona", "uge"};
public CellRender(){
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con = frame.getContentPane();
jcb = new JComboBox(items);
jcb.setRenderer(new ItalicRenderer());
con.add(jcb, BorderLayout.SOUTH);
frame.setSize(300, 300);
frame.setVisible(true);
}
public static void main(String[] args){
new CellRender();
}
}
class ItalicRenderer extends DefaultListCellRenderer{
public Component getListCellRendererComponent
(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus){
Font newFont;
super.getListCellRendererComponent(list, value,
index, isSelected, cellHasFocus);
Font font = getFont();
String item = (String)value;
newFont = font.deriveFont(Font.ITALIC);
setFont(newFont);
setText(item);
return this;
}
}
---------------
.
- Follow-Ups:
- Re: JComboBox cell renderer doesn't render the top item
- From: Kari Ikonen
- Re: JComboBox cell renderer doesn't render the top item
- From: Roedy Green
- Re: JComboBox cell renderer doesn't render the top item
- From: Rene Ruppert
- Re: JComboBox cell renderer doesn't render the top item
- Prev by Date: mouseDragged() sensitivity?
- Next by Date: Re: JComboBox cell renderer doesn't render the top item
- Previous by thread: mouseDragged() sensitivity?
- Next by thread: Re: JComboBox cell renderer doesn't render the top item
- Index(es):