Re: Can the content of JComboBox be RightAlignment



This is what I could think of.
cb.setRenderer(new MyCellRenderer());
......
class MyCellRenderer extends JLabel implements ListCellRenderer {
Color bg;
public MyCellRenderer() {
super("", JLabel.RIGHT );
setOpaque(true);
bg = this.getBackground();
}
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus)
{
setText(value.toString());
setBackground(isSelected ? Color.YELLOW : bg );
return this;
}
}
Color handling could be improved.
Anyone know an easier/shorter way ?
--------------------
Paul Hamaker, SEMM, teaching ICT since 1987
http://javalessons.com

.