java - JButton 文本在不同的单词中具有不同的字体系列

标签 java html swing fonts

我正在尝试实现一个按钮,其文本具有两种不同的字体系列。

我认为,它可以使用 HTML 来实现,如本页所述。 http://docs.oracle.com/javase/tutorial/uiswing/components/html.html

我试过下面的代码,但它不工作。

JButton button = new JButton("<html>Hello <font family=Serif>World</font></html>");

可能是font标签属性family错误!

最佳答案

May be the font tag attribute family is wrong!

确实如此,正确的标签应该是:

<font face="Serif"></font>

查看HTML font tag .所以在你的情况下:

JButton button = new JButton("<html>Hello <font face=\"Serif\">World</font></html>");

图片

enter image description here

关于java - JButton 文本在不同的单词中具有不同的字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21046164/

相关文章:

Java 和 REST Web 服务 - GET 方法返回 JSONObject ["....."] 不是 JSONObject

java - 如何诊断 JBoss IIOP Stub 生成、类加载问题?

javascript - 无法使用 javascript (html) 调用 WebMethod

居中 div 内的 HTML 表格无法正确显示

java - Java 中的 BorderLayout() 问题

Java 和 "Type Safety..."

java - Elasticsearch Rest 客户端仍然给出 IOException : Too Many Open Files

javascript - 在 Angular 中重新加载图像

java - 从字符串动态创建类中的对象

java - 基于一个变量显示多个jPanel