Naeem Baghi Naeem Baghi - 1 month ago 13
Java Question

Is there any way to right align the text in a JCombobox

I want to have a JComboBox with right align. how can I do that?
someone before said "You can set a renderer to the JComboBox which can be a JLabel having JLabel#setHorizontalAlignment(JLabel.RIGHT)" but I don't know how can I do that?

Answer

someone before said "You can set a renderer to the JComboBox which can be a JLabel having JLabel#setHorizontalAlignment(JLabel.RIGHT)"

Yes, the default renederer is a JLabel so you don't need to create a custom renderer. You can just use:

((JLabel)comboBox.getRenderer()).setHorizontalAlignment(JLabel.RIGHT);
Comments