【发布时间】:2014-05-25 14:54:22
【问题描述】:
当我使用此代码时,它不起作用;文本不会变为粗体。为什么?
label1 = new JLabel();
label1.setText("Welcome, <html><strong>Hussein</strong></html>.");
【问题讨论】:
当我使用此代码时,它不起作用;文本不会变为粗体。为什么?
label1 = new JLabel();
label1.setText("Welcome, <html><strong>Hussein</strong></html>.");
【问题讨论】:
您的 HTML 语法不好,因为您的 String 不是以 html DOM 根开头的。
尝试以下几行:
label1.setText("<html>Welcome <strong>Hussein</strong>.</html>");
查找教程here。
【讨论】:
试试这个:
JLabel label = new JLabel("<html><yourTagHere><yourOtherTagHere>this is your text</yourOtherTagHere></yourTagHere></html>");
【讨论】:
你忘了加body标签,试试这个:
label1 = new JLabel();
label1.setText("<html><body>Welcome ,<strong> Hussein</strong></body></html>");
【讨论】:
为什么要混合 html 和 java。标签在html中。这就是你在java中的做法
label = new JLabel("A label");
label.setFont(new Font("Serif", Font.BOLD, 14));
【讨论】: