views:

249

answers:

2

What's the best way to insert statistics symbols in a JLabel's text? For example, the x-bar? I tried assigning the text field the following with no success:

<html>x&#772;

Thanks.

+1  A: 

Well, that's completely mal-formed HTML, probably even for Swing (I think you would need the </html> at the end for it to work. But I would try to never go that road if you can help it, as Swing's HTML support has many drawbacks and bugs.

You can probably simply insert the appropriate character directly, either directly in the source code if you're using Unicode or with the appropriate Unicode escape:

"x\u0304"

This should work, actually. But it depends on font support and some fonts are pretty bad in positioning combining characters. But short of drawing it yourself it should be your best option.

Joey
+5  A: 

Html codes will not work in Java. However, you can use the unicode escape in Java Strings.

For example:

JLabel label = new JLabel(new String("\u0304"));

Also, here is a cool website for taking Unicode text and turning it into Java String leterals.

jjnguy