6

テキストを含む JLabel があり、それに別のテキストを追加したいのですが、後者は前者とは異なる色 (赤など) になります。私はもう試した:

statusLabel.setText(statusLabel.getText() +
  " <html><span style\"color: red\">" + message + "</span></html>");

しかし、うまくいきません。HTML タグを表示するだけで、レンダリングはしません。助言がありますか?JLabel の一部のテキストの色を変更することはできますか?

4

1 に答える 1

10

これを試して:

setText("<html>Some text <font color='red'>some text in red</font></html>");

または、次のように文字列を作成できます。

statusLabel.setText(String.format("<html>%s<font color='red'>%s</font></html>", 
        statusLabel.getText(), message));
于 2012-04-26T00:16:42.430 に答える