【问题标题】:Include the minus superscript in a JButton's text在 JButton 的文本中包含减号上标
【发布时间】:2015-05-13 01:05:28
【问题描述】:

我正在尝试将我的 JButton 的文本设置为 UTF-8 编码的“Compute b⁻¹ (mod a)”,但这两种尝试都不起作用。问题是负上标,但不确定我能做什么。

尝试 1:

_computeModInverseButton = new JButton("Compute b⁻¹ (mod a)");

尝试 2:

    _computeModInverseButton = new JButton("Compute b<html><sup>-1</sup></html> (mod a)"); 

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

_computeModInverseButton = new JButton("Compute b-1 (mod a)");

看起来像

我怎样才能格式化它以适应上标?

【问题讨论】:

  • 如果你用 html 来做整个事情呢? new JButton("&lt;html&gt;Compute b&lt;sup&gt;-1&lt;/sup&gt; (mod a)&lt;/html&gt;")
  • 成功了,谢谢。天才……哈哈。

标签: java html swing jbutton superscript


【解决方案1】:

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>");

【讨论】:

  • 我更新了我的问题,询问如何正确格式化按钮的文本,包括 html 上标,你知道这样做的好方法吗?
【解决方案2】:

根据我的评论,您应该将整个字符串包装在 HTML 中:

JButton myButton = new JButton("<html>Compute b<sup>-1</sup> (mod a)</html>");

【讨论】:

  • 我更新了我的问题,询问如何正确格式化按钮的文本,包括 html 上标,你知道这样做的好方法吗?
【解决方案3】:

已解决:所有文本都需要在 html 标签中。

_computeModInverseButton = new JButton("计算 b-1 (mod a)");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-26
    • 1970-01-01
    • 1970-01-01
    • 2020-06-24
    • 2013-01-06
    • 2014-06-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多