Reputation: 11
I have tried all kinds things but nothing is working. Netbeans is always displaying a " ? " instead of the symbol itself ♤ ♡ ♢ ♧
My project is encoded UTF-8.
I changed to font for the Output window to Segoe UI Symbol. It's still printing < ? >
My code:
Upvotes: 1
Views: 1353
Reputation: 17373
You probably just need to specify a font for the Output window that can render the characters "♤ ♡ ♢ ♧". One such font is Segoe UI Symbol, and to set that as the font in the Output window:
Then just run your application again, and the characters will be rendered correctly in the Output window:
If that doesn't resolve your problem, please update your question to show your code.
Updated on 1/5/20, based on OP feedback:
To render the playing card symbols in the Output window:
-J-Dfile.encoding=UTF-8
to the end of the property value for netbeans_default_options
(just before the closing quote).System.out
must support UTF-8. This can be achieved in two different ways:
-Dfile.encoding=utf-8
for Properties > Run > VM Options so that the default PrintStream
uses UTF-8 encoding at run time.PrintStream
instead. See the code below for the details.Here's the code:
package com.unthreading.emojimaven;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;
public class App {
public static void main(String[] args) throws UnsupportedEncodingException {
String symbPique = "\u2660";
String symbCoeur = "\u2665";
String symbCarreau = "\u2666";
String symbTrefle = "\u2663";
System.out.println("System.getProperty(\"file.encoding\")=" + System.getProperty("file.encoding"));
System.out.println("StandardCharsets.UTF_8.name(): " + StandardCharsets.UTF_8.name());
System.out.println("Charset.defaultCharSet()=" + Charset.defaultCharset());
System.out.println("Default PrintStream: " + symbCarreau + "--" + symbCoeur + "--" + symbPique + "--" + symbTrefle);
PrintStream outStream = new PrintStream(System.out, true, StandardCharsets.UTF_8.name());
outStream.println("UTF-8 PrintStream: " + symbCarreau + "--" + symbCoeur + "--" + symbPique + "--" + symbTrefle);
}
}
Here's the output when project's VM Options is set to -Dfile.encoding=utf-8
:
------------------------------------------------------------------------
Building emojimaven 1.0-SNAPSHOT
------------------------------------------------------------------------
--- exec-maven-plugin:1.5.0:exec (default-cli) @ emojimaven ---
System.getProperty("file.encoding")=UTF-8
StandardCharsets.UTF_8.name(): UTF-8
Charset.defaultCharSet()=UTF-8
Default PrintStream: ♦--♥--♠--♣
UTF-8 PrintStream: ♦--♥--♠--♣
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 0.717 s
Finished at: 2020-01-05T00:21:16-05:00
Final Memory: 7M/60M
------------------------------------------------------------------------
Notes:
Upvotes: 0