1

When I run my project under NetBeans it works, and the Arabic text is formatted correctly. But when I build the project and send it to the client, the Arabic text is reversed.

The same thing also happens to me. When I open the jar file of the project, I see that the language is reversed. I need a solution knowing that Arabic words are written inside jLabel.

When I run the project from within NetBeans, these are the correct results:

NetBeans Run Result

And these are the incorrect results when I open the jar file after building the project:

jar File Result After Building The Project

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • If I have to guess, it would be an encoding issue in the operating system. Netbeans is probably using the proper encoding (For example UTF_16) in its settings – JCompetence Jan 15 '22 at 14:45
  • How do I change the encoding in NetBeans – Youssef Ahmed Jan 15 '22 at 14:49
  • Why do you want to change NetBeans..it is working properly there.. You need to see how you are working with Strings in your java code (Used for translations), are you doing any encoding specifically, for example new String (..., UTF-16), or are you depending on the OS encoding? Please see https://stackoverflow.com/questions/4133195/how-to-change-file-encoding-in-netbeans for netbeans.. Also if you are using Maven, or Gradle, then you can set resource encoding there as well – JCompetence Jan 15 '22 at 14:51
  • 1
    @SMA If it’s the same characters appearing in reverse order, it has nothing to do with UTF-16 or any other charset. It’s more likely the [ComponentOrientation](https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/java/awt/Container.html#applyComponentOrientation(java.awt.ComponentOrientation)). – VGR Jan 15 '22 at 14:58
  • @VGR You might be correct, however that would be strange if the ComponentOrientation acts different in Netbeans vs OS...it would be interesting to find out, but you make a valid point – JCompetence Jan 15 '22 at 15:04
  • @VGR You are right, but what is the solution? – Youssef Ahmed Jan 15 '22 at 15:10
  • Try adding this right before you call `pack()` on your Frame: `frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));` (I assume the default locale of everyone running an Arabic application will be a right-to-left locale.) – VGR Jan 15 '22 at 15:15
  • But guys, have you noticed that some of the JLabel are reversed and some are not, and this is strange and confusing in the matter – Youssef Ahmed Jan 15 '22 at 15:17
  • @VGR I put the code in formWindowOpened it shows me an error in the word frame which is at the beginning – Youssef Ahmed Jan 15 '22 at 15:22
  • Replace `frame` with the variable which contains your Frame or JFrame. If you are extending Frame or JFrame directly, use `this`. – VGR Jan 15 '22 at 15:36
  • JFrame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); // Frame name is orders orders.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Write it in the first way, or the second way, or the other way, because the two give me an error, knowing that the name of the frame is orders – Youssef Ahmed Jan 15 '22 at 15:43

1 Answers1

1

Well guys, I finally discovered the error which is the font type. I put the font type in NetBeans (Times New Roman) And I discovered that NetBeans supports this type of font, but Windows does not support it, so it makes the sheep inverted and only this problem and I hope that no one will fall into this slander after me: and it is better to use this type of font (Tahoma) because all devices support it And it does not show any problem, thank you

  • 2
    *"**(Tahoma)** because all devices support it"* That's a dangerous assumption to make, given it originated on Windows especially. In *all* cases where a specific font is required, it is advisable to supply it with the app. and load it at run-time. See [this answer](https://stackoverflow.com/a/8365030/418556) for source code that does that. – Andrew Thompson Jan 17 '22 at 15:45