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:
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.
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