0

My Java Application contains Label which shows emoticons and Textfields which shows some information in other language i.e Hindi When i run it from my IDE (Netbeans) it shows emoticons , Text in Textfields correctly Application Run from IDE

But when i build it and run directly from .JAR it shows some characters like this

Application Built

I have already set the font but it works only with IDE but not after building. Textfield also shows the same unrecognizable character same as the above label Made With BY DEMO

Hritik R
  • 73
  • 6
  • @camickr how can i check that out? – Hritik R Apr 18 '21 at 15:12
  • Edit your question and show the code which generates the text for the “Made With” component. I suspect you are creating a String from bytes without specifying a charset. – VGR Apr 18 '21 at 15:39
  • @VGR I'm directly setting text for label from properties tab. as the answer below mention about using UTF-8 . is there a way i can set it for the whole application while building it. – Hritik R Apr 18 '21 at 15:42
  • That answer merely works around what is likely a mistake in your code. Is there not a .java file that calls the `setText` method of your JLabel? – VGR Apr 18 '21 at 15:44
  • @VGR it have a java file. i got your point that i need to set charset for the label. as i'm a beginner i don't know how to do that. here's the code - `jlabel1.setText("Made With By DEMO");` – Hritik R Apr 18 '21 at 15:51
  • 1
    Can I assume you meant to write `jlabel1.setText("Made With ♥ By DEMO");`? – VGR Apr 18 '21 at 15:52
  • @VGR yes thats correct – Hritik R Apr 18 '21 at 15:54
  • 1
    The proper fix is to make sure your source file is interpreted correctly at compile time. If you compile on the command line, use `-encoding UTF-8`. For example: `javac -encoding UTF-8 Developer.java` See https://stackoverflow.com/questions/1726174/how-to-compile-a-java-source-file-which-is-encoded-as-utf-8. Once the class is compiled, the String constants in the compiled .class file are correct no matter how or where they’re run, since a Java runtime always interprets them in the same way. – VGR Apr 18 '21 at 16:00
  • @VGR Thanks alot i got it – Hritik R Apr 18 '21 at 16:03

1 Answers1

0

You can try file.encoding option, while running the jar file.

java -Dfile.encoding="UTF-8" -jar MyApplication.jar
Mehmet Bektaş
  • 173
  • 1
  • 2
  • 15