在JButton的文本中包含减号

Kol*_*rie 0 html java swing superscript jbutton

我试图用JBF-8编码将我的JButton的文本设置为"Compute b--¹(mod a)",但这两个尝试都不起作用.问题是减号,但不确定我能做什么.

尝试1:

_computeModInverseButton = new JButton("Compute b?¹ (mod a)");
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

尝试2:

    _computeModInverseButton = new JButton("Compute b<html><sup>-1</sup></html> (mod a)"); 
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

所以问题是我的HTML格式,但现在有了

_computeModInverseButton = new JButton("Compute b-1 (mod a)");
Run Code Online (Sandbox Code Playgroud)

看起来像在此输入图像描述

如何格式化以适应上标?

Pet*_*ans 5

请参阅https://docs.oracle.com/javase/tutorial/uiswing/components/html.html

要指定组件的文本具有HTML格式,只需将标记放在文本开头,然后在其余部分中使用任何有效的HTML.以下是在按钮文本中使用HTML的示例:

button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");
Run Code Online (Sandbox Code Playgroud)