Re: Can the content of JComboBox be RightAlignment



cl wrote:
Hi,everybody

As the title, is there any methods?
I just tried, but no finding.

regards,
poorrichard

A ListCellRenderer takes care of rendering the combobox items. Class
BasicComboBoxRenderer (the default implementation of the
ListCellRenderer interface) extends JLabel. For right alignment, you
could try the following code

<untested>

JComboBox yourComboBox = new JComboBox();

ListCellRenderer itemRenderer = yourComboBox.getRenderer();

if (itemRenderer instanceof JLabel) {
JLabel itemRendererLabel = (JLabel)itemRenderer;
itemRendererLabel.setHorizontalAlignment(SwingConstants.RIGHT);
}


</untested>

Regards,

Roland
.