javaunicodecharacterchars

How to handle unicode chars in Java


I have been trying to achieve the following :

I want to be able to paste a string of Unicode characters ex : πŸ–•πŸΌπŸ™…πŸ½ without java showing them as being unrecognized. How do I make a Java JTextPane able to handle Unicode characters?


Solution

  • If you want to use Unicode character you have to write it like this: \u[unicode]. So for example:

     JOptionPane.showMessageDialog(null, "\u2764Guess number", "game", JOptionPane.INFORMATION_MESSAGE);
    

    would produce the folowing: ❀Guess number. I hope I answered your question.