Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I show the pound sterling (£) sign in Java Swing?

Currently, I add a pound sterling (£) sign to the Java source and compile the resulting Swing component shows as the square (unsupported character) symbol.

I suspect it's an encoding problem, the Java source file is encoded as cp1252 (Eclipse seems to default to this). What's the correct way of resolving this?

like image 705
Pool Avatar asked Dec 14 '22 03:12

Pool


2 Answers

Use the \u00A3 notation. Further examples here for the unicodes Unicode code points for other symbols.

like image 194
akarnokd Avatar answered Dec 15 '22 17:12

akarnokd


I believe you can change the source code's encoding from Eclipse (or from any decent editor). Set it to UTF-8. Then everything should behave smoothly, because Java Strings are Unicode.

I would strongly encourage using proper encoding in the source, instead of this \uXXX notation. The reason being, how on earth do you infer form the code what for instance \u00A3 means? It's much clearer to just put the correct character there.

like image 34
Joonas Pulakka Avatar answered Dec 15 '22 17:12

Joonas Pulakka