5

I have the following text:

وزا.word

But when displaying it on my JTable it looks like this:

word.وزا

In every JLabel or TextArea or any other input it does look like the original text:

وزا.word

ONLY on the JTable I am having such problem.

I do not care if it is making sense or not, and yes I know the Arabic Language is written from right to left. My guess is Java is detecting it and automatically inverting it, but I do not want it to.

Note: I have no idea what وزا means, and for practical purposes I don't care. It's also irrelevant for this case wether وزا.word does not make sense and word.وزا does or viceversa.

Note 2: The text, reversed or not is always aligned to the left (as I expect it to).

Thanks in advance.

George W
  • 187
  • 9
  • For better help sooner, post an [SSCCE](http://sscce.org/). I guess part of the problem is that it does not really make sense to mix both Left-to-Right & Right-to-Left text styles (guessing that is ..Arabic characters beside the English?). Could you not represent one as a tool-tip? – Andrew Thompson Jul 11 '13 at 15:14
  • I am curious to see the screen that shows the above description. Can u please share it. – Amarnath Jul 11 '13 at 15:15
  • Which Java version are you using. A JLabel should also render that string with the Latin characters to the left of the Arab word. – jarnbjo Jul 11 '13 at 15:19
  • @jarnbjo that's what the OP says; the problem seems to be with `JTable`. – fge Jul 11 '13 at 15:20
  • @fge: Perhaps even different browsers render his question differently. Here, his question reads that JTable renders the Latin word left of the Arab word, while JLabel and TextArea renders the Arab word left of the Latin word. – jarnbjo Jul 11 '13 at 15:23
  • @jarnbjo same here; I don't believe browser rendering enters into account here (if it did I'd be surprised!) – fge Jul 11 '13 at 15:24
  • *"(guessing that is ..Arabic.."* (Note to self) 'Intuitively obvious' if you read either the title *or* the body. :P – Andrew Thompson Jul 11 '13 at 15:28
  • I forgot to mention it is JTable as a swing component, so yeah there are no browsers involved. I am using Java version 7 btw. – George W Jul 11 '13 at 16:35
  • again for better help sooner, post an SSCCE, 1. there is one bug with one of Arabic glyphs, 2. maybe not related – mKorbel Jul 11 '13 at 20:16

1 Answers1

5

At a guess, your default Locale is giving the default renderer a ComponentOrientation that is inconsistent with your other settings. You might try creating a custom renderer having the preferred orientation using one of the approaches suggested here.

Addendum: java.text.Bidi supports bidirectional reordering; you may be able to use unicode format control code points, as suggested in this Q&A.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I am currently attempting this at the moment, with no luck. Also, isn't the orientation more about the alignment of the text rather than the way it is printed? Wether وزا.word or word.وزا it is always aligned to the left (as I expect it to). – George W Jul 11 '13 at 19:48
  • `java.text.Bidi` supports bidirectional reordering; IIRC, the tutorial example `TextComponentDemo` uses a `DocumentListener` to display some details; see also this [Q&A](http://stackoverflow.com/q/6177294/230513).. – trashgod Jul 11 '13 at 23:24
  • You should add this last comment as an answer...so I can mark it as solved because it did work!! Thank you very much trashgod. I'll await your specific reply to mark it as solved. – George W Jul 12 '13 at 22:06
  • @GeorgeW: I am facing now the same problem, how can the solution you found? Could you please explain me? – SagittariusA May 13 '21 at 08:31
  • @SagittariusA: Custom components are a very broad topic, and I'm not sure about the problem you are now facing. You might get more widespread attention if you were to [ask](https://stackoverflow.com/questions/how-to-ask) a question, perhaps citing the work mentioned here and adding a [mcve] showing your specific problem. – trashgod May 13 '21 at 16:14
  • @trashgod thank you for your kind reply. Yesterday I forgot to link the question I posted, where you should find what you required https://stackoverflow.com/questions/67515783/jtable-inverts-words-when-text-contains-mixed-arabic-and-western-characters – SagittariusA May 14 '21 at 07:01