【问题标题】:JButton - How can I break the line and set two different text sizes in the same button?JButton - 如何在同一个按钮中换行并设置两种不同的文本大小?
【发布时间】:2015-06-30 21:01:30
【问题描述】:

我想将两种文本类型放在一个按钮中.. 上一个是一个大数字,下一个是一个较小的文本。 下面的代码已经换行了,但是我无法操作字体。

String twoLines = "Two\nLines";
JButton b = new JButton("<html>" + twoLines.replaceAll("\\n", "<br>") + "</html>");

【问题讨论】:

    标签: button text jbutton font-size line-breaks


    【解决方案1】:

    我想将两种文本类型放在一个按钮中。上面的会是一个大数字,下面的会是一个较小的文本。

    这只是 html/css 样式的问题。您可以使用包含必要样式的 span 元素围绕要设置样式的文本

    JButton button = new JButton("<html>Top<br /><span style=\"font-size: 0.9em\">bottom</span></html>");
    

    或者,您可以使用段落元素创建新行,并根据需要设置段落样式。

    JButton button = new JButton("<html><p>Top</p><p style=\"font-size:0.9em\">Bottom</p></html>");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-02
      • 1970-01-01
      • 2018-03-07
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 2020-04-07
      • 1970-01-01
      相关资源
      最近更新 更多