JList display Hebrew right-to-left
I have a JList and I want it to display Hebrew text starting on the right hand side. I've tried 2 different methods and each one displays the text from the left hand side, like English.
First I tried a simple approach:
Code :
ListCellRenderer cellRen1 = jList1.getCellRenderer();
JLabel ren2 = (JLabel) cellRen1;
ren2.setHorizontalTextPosition(JLabel.RIGHT);
jList1.setCellRenderer(cellRen1);
I could see the object number of cellRen1, which I cast to a JLabel. Then I set the direction to Hebrew. The forth line doesn't really do anything since I am putting back the same object. In any case, it didn't work.
Next I tried making a ListCellRenderer. I checked in the debugger that it was being called for each string to be displayed. Only the first time did I see a change in the value of setHorizontalTextPosition. After I set it, it stayed set, but the text still displayed as English in direction.
Code :
private void init1() {
ListCellRenderer rend1 = new HebrewCellRenderer();
jList1.setCellRenderer(rend1);
}
class HebrewCellRenderer implements ListCellRenderer {
protected DefaultListCellRenderer defRen = new DefaultListCellRenderer();
@Override
public Component getListCellRendererComponent(JList jlist, Object o, int i, boolean bln, boolean bln1) {
JLabel rend1 = (JLabel) defRen.getListCellRendererComponent(jlist, o, i, bln, bln1);
rend1.setHorizontalTextPosition(JLabel.RIGHT);
return rend1;
}
}
The question is: why doesn't the text display right-to-left?
Thanks,
Ilan
Re: JList display Hebrew right-to-left
Hmmm.... I was in the same problem almost one and a half year ago, i was working on J2ME localization. I somehow managed to handle this. I can't remember at the moment. I have to see my code once again.....
Well, i will get back to you.
Meanwhile, you try to manage all this with the help of UNICODES for the local language.
As far as i know, i did this work with the help of unicodes.
And direction is not only with JLabel.RIGHT, there is something else that has to put in the code, to make it work from Right to Left.
Re: JList display Hebrew right-to-left
Thanks for the reply.
I have no problem with the Hebrew itself, that displays just fine. Just it is in the wrong direction.
I read the strings from a database (mySQL) and they come out correctly.
If you can find out what is the added secret, that would be great.
I can get combo boxes and text boxes to come out correctly, just JList is a problem.
Re: JList display Hebrew right-to-left
In the hope that this might help somebody else, one doesn't need the setHorizontalTextPosition (and it doesn't help anyway). What one needs is
Code :
jList1.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);