• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to Achieve Right-to-Left Text in JLabel ?

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.5.0_05 on Windows 2000
Using method "setComponentOrientation" appears to have no effect.
The label needs to display a combination of Latin and Hebrew text as well as punctuation and digits.
If the first character is Latin, the text is not displayed as intended.
For example

ABC123אבג

is displayed as

אבגABC123

Tried using HTML and the "dir" attribute of the HTML tag but it is not supported.

Thanks,
Avi.
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the horizontal alignment.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avi Abrami wrote:JDK 1.5.0_05 on Windows 2000
Using method "setComponentOrientation" appears to have no effect.
The label needs to display a combination of Latin and Hebrew text as well as punctuation and digits.
If the first character is Latin, the text is not displayed as intended.

You mean if the entire text is Hebrew, then it displays RTL, and if the entire text is Latin, then it displays LTR, and if there's a combination of Hebrew and Latin then the first character is used to decide between RTL and LTR? Is that how it's actually working?
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's also some ambiguity in your example:
Avi Abrami wrote:ABC123אבג

Does this represent a String object with the characters A, B, C, 1, 2, 3, alef, bet, gimel, or does it represent a String object with the characters A, B, C, 1, 2, 3, gimel, bet, alef?

(I was having trouble with the Hebrew characters when I tried to type them because Firefox wanted to RTL them while LTR-ing the rest of the post. Which is the right thing to do, I think, and it's related to your question. That's why you need to clarify.)
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
Setting horizontal alignment does not help, i.e...


Paul,

You mean if the entire text is Hebrew, then it displays RTL, and if the entire text is Latin, then it displays LTR, and if there's a combination of Hebrew and Latin then the first character is used to decide between RTL and LTR? Is that how it's actually working?

You are correct.

Does this represent a String object with the characters A, B, C, 1, 2, 3, alef, bet, gimel ?

Yes.

Thanks for your help so far.

 
Noms Dom
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try the following
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you actually read the starting post and find out that Avi already tried that.

Avi, can you add a (Line)Border to the JLabel temporarily? Perhaps the horizontal alignment does work but the JLabel is only as big as its text. If this is the case then you should check out the parent container's layout manager instead.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,
I added a line border to the JLabel.
The label text is still displayed not as I intended.
It would seem that no-one reading this post has had to overcome this problem.
And from the results of my Internet searching, if there is anyone who has successfully overcome this problem, then [s]he has not shared his (or her) solution online.

Thanks for your efforts to help me.

Cheers,
Avi.
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now also on the Sun/Oracle forums, with acknowledgement.
http://forums.sun.com/thread.jspa?threadID=5444279
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avi, could you notify us of any follow-ups on other forums as well? Without Darryl we wouldn't know if anyone on the Sun forum would find a solution, and someone might still try to help you unnecessarily.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!