Reputation: 149
I am trying to set the text of my JButton to "Compute b⁻¹ (mod a)" in UTF-8 encoding, but neither of these two attempts work. The problem is the minus superscript, but not sure what I can do.
Attempt 1:
_computeModInverseButton = new JButton("Compute b⁻¹ (mod a)");
Attempt 2:
_computeModInverseButton = new JButton("Compute b<html><sup>-1</sup></html> (mod a)");
So the problem was my HTML formatting, but now with
_computeModInverseButton = new JButton("Compute b-1 (mod a)");
It looks like
How can I format this to fit well with the superscript?
Upvotes: 0
Views: 665
Reputation: 285403
As per my comment, you should wrap the whole String in HTML:
JButton myButton = new JButton("<html>Compute b<sup>-1</sup> (mod a)</html>");
Upvotes: 2
Reputation: 149
Solved: all text needed to be in the html tags.
_computeModInverseButton = new JButton("Compute b-1 (mod a)");
Upvotes: 0
Reputation: 35331
see https://docs.oracle.com/javase/tutorial/uiswing/components/html.html
To specify that a component's text has HTML formatting, just put the tag at the beginning of the text, then use any valid HTML in the remainder. Here is an example of using HTML in a button's text:
button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");
Upvotes: 5