0

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:

Screen shot of code

skomisa
  • 16,436
  • 7
  • 61
  • 102

1 Answers1

0

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:

  • Tools > Options > Miscellaneous > click the Output tab > Font
  • Set the font to Segoe UI Symbol and click OK.

Then just run your application again, and the characters will be rendered correctly in the Output window:

outputWindow

If that doesn't resolve your problem, please update your question to show your code.


Updated on 1/5/20, based on OP feedback:

  • Changing the font did not help, and with hindsight this was not necessary anyway.
  • The issue relates only to Maven projects in NetBeans. Ant projects don't have this problem.

To render the playing card symbols in the Output window:

  • In the NetBeans configuration file etc/netbeans.conf, append -J-Dfile.encoding=UTF-8 to the end of the property value for netbeans_default_options (just before the closing quote).
  • Save the change and then restart NetBeans.
  • The PrintStream used by System.out must support UTF-8. This can be achieved in two different ways:
    1. Open the project's properties, and set -Dfile.encoding=utf-8 for Properties > Run > VM Options so that the default PrintStream uses UTF-8 encoding at run time.
    2. Alternatively, in the code create and use a UTF-8 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:

  • The change to netbeans.conf is essential, so that NetBeans configures the Output window for UTF-8 during startup.
  • The default font for the Output window is Monospaced. Since that renders the playing card symbols correctly there is no need to change it, at least for the requirement given in the OP.
  • There is no need for any special settings in pom.xml.
skomisa
  • 16,436
  • 7
  • 61
  • 102
  • Did what you suggested. Still not working. I edited my question and showed my simple code. – mickyyyyyz Jan 02 '20 at 20:21
  • @mickyyyyyz OK. [1] My example worked because I created an Ant project. I can reproduce your problem with a Maven project, though I'm not sure what's causing it yet. [2] The SO question [Maven: Source Encoding in UTF-8 not working?](https://stackoverflow.com/q/17656475/2985643) might be helpful for you, though it didn't help me. [3] Can you post your code as text (not a screen shot), and also your **pom.xml**? – skomisa Jan 03 '20 at 09:00