[英]How to change the color of particular characters in JLabel?
如何更改JLabel中特定字符的顏色? 例如,
JLabel lbl = new JLabel("My Text");
我希望My
有藍色,而Text
有紅色。 可能嗎?
是的,請查看如何在Swing組件中使用HTML 。
JLabel lbl = new JLabel("<html><font color=blue>My</font><font color=red>Text</font></html>");
試試html:
String labelText =
"<html><FONT COLOR=BLUE>My</FONT>" +
"<FONT COLOR=RED>Text</FONT></html>";
JLabel lbl = new JLabel(labelText);
您可以在JLabels中使用HTML,因此這應該有效:
JLabel lbl = new JLabel("<html><span style='color: blue;'>My</span> <span style='color: red;'>Text</span></html>");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.