JList and JComboBox elements - right alignment
Hi!
If one wants to enter text into JTextField from right to left, he uses:
JTextField jtf = new JTextField();
jtf.setHorizontalAlignment(JTextField.RIGHT);
I want elements of JTextField and JComboBox(text in my case) to appear from right to left. What can I do?
Best regards,
Nemaria.
[336 byte] By [
nemaria] at [2007-9-26 2:20:47]

Create an extension of DefaultListCellRenderer that aligns the way you want. For example:
JList list = new JList(...);
list.setCellRenderer(new RightAlignedListCell());
...
class RightAlignedListCell extends DefaultListCellRenderer
{
public Component getListCellRendererComponent(
JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus)
{
// Call the superclass to get a renderer that is correct for the current look-and-feel.
JLabel cell = (JLabel) super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus);
cell.setHorizontalAlignment(JLabel.RIGHT);
return cell;
}
}
Mitch Goldstein
Author, Hardcore JFC (Cambridge Univ Press)
mdgoldstein@hotmail.com