LaLa
LaLa

Reputation: 121

Arabic in java error

I'm working currently on java project that uses Arabic Language, I found difficulty in writing in Arabic as shown in the image:

enter image description here

  1. I wrote Arabic without any edit.
  2. I added a reverse() method, it worked good but the letters aren't attached to each other, they're separate.

    StringBuilder input = new StringBuilder();
    input.append(jTextField2.getText());
    input = input.reverse();
    jTextField1.setText(input.toString());
    
  3. I use site the flip the text, it didn't work as well.

  4. I use the same site, but with jLabel it worked.

other method I use, but didn't work:

Can anyone help me how to write & print Arabic in java correctly?

Upvotes: 1

Views: 568

Answers (2)

bmargulies
bmargulies

Reputation: 100161

A string entirely composed of characters from the Arabic block should render with correct RTL presentation without any directionality control characters. If it does not, it is likely that you have a problem with your operating system configuration, not with your Java code. Reversing the string is a terrible idea. Trying for visual-order rendering is going to get all messed up.

Upvotes: 1

Tamir Adler
Tamir Adler

Reputation: 421

Please refer to this question - Forcing RTL order in a JTextArea

Here is a sugestion to start the string with the character \u202e to force the text to be RTL.

Also i think it is not good approach to reverse the string, as it is not good user experience when the user do "copy paste", as he will copy reversed string...

Upvotes: 1

Related Questions