Re: Can the content of JComboBox be RightAlignment
- From: ph@xxxxxxxxxxxxxx
- Date: 27 Feb 2006 04:13:08 -0800
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
.
- Follow-Ups:
- Re: Can the content of JComboBox be RightAlignment
- From: Andrey Kuznetsov
- Re: Can the content of JComboBox be RightAlignment
- References:
- Prev by Date: Re: Can the content of JComboBox be RightAlignment
- Next by Date: Re: Can the content of JComboBox be RightAlignment
- Previous by thread: Re: Can the content of JComboBox be RightAlignment
- Next by thread: Re: Can the content of JComboBox be RightAlignment
- Index(es):