show super script / subscript in combo box and table

Hi All,

I was just wondering if it was possible to show a superscript/subscript value in a combo box and in a table.

In the combo box, I want to show different units such as cubic metres and cubic feet. So I want it to look like a m with a superscript 3 on top.

I also want to see this information in a table as well.

Is this possible?


Unicode has characters for numeric superscripts. The x² and x³ are actually also in ISO-8859-1.

Unicode subscripts and superscripts

Items in ComboBox can not be HTML. In Table, you can put Label components in XHTML content mode. It’s not possible to have HTML in Table header though. Well, with client-side modifications everything is possible.

Is it possible to set a different unicode on an item for Combo Boxes to show superscript?
Or any other way besides using HTML for a combo box?

Set a different Unicode? Sorry, didn’t understand.

You can set the item caption in many ways. One possibility:

ComboBox combobox = new ComboBox("Some caption");
combobox.addItem("area in m²");
combobox.addItem("volume in m³");

Just make sure your source files are in UTF-8. Well the m² and m³ work also in ISO-8859-1, but other codes do not. In Eclipse, you can set the source file encoding in the project properties.

Sorry I am getting kinda confused.
I know how to set the caption, but how did you make it superscript like that?
LIke in Eclipse and Java, you can’t just type in a superscript string can you?

Well yes, you can just type them in, although different operating systems allow typing ANSI or Unicode codes from keyboard a bit differently. For example in Linux/KDE, you hold Ctrl+Shift down and type “u00b2”, which results in ². In Windows, hold down Alt while typing +00b2 (you need to press + on the numeric keyboard, not the other one).

Some keyboard layouts might even give such characters with some AltGr combination.

Or you can just copy&paste.

Thanks so much for the explanation.
Helped me alot.
I honestly didn’t know you could just copy and paste some superscript value in to java. I thought it was something special in a string, but either way, thank you so much!