我应该如何处理这个字符串
?
欺骗宝珠范围:880 冷却时间:7 成本:70/75/80/85/90 法力
我想要颜色为蓝色、尺寸为 14 的 “欺骗之球”
和 “范围”
/“冷却”
/“Cost”
颜色为黑色,尺寸为 12,数字为绿色,尺寸为 10。
它必须包含在一个 JLabel
中。
这可能吗?
最佳答案
E.G. (根据需要调整)
import java.awt.*;
import javax.swing.*;
class ColoredLabel {
static String text =
"<html>"
+ "<head>"
+ "<style type='text/css'>"
+ ".name {"
+ " font-size: 16px;"
+ " color: blue;"
+ "}"
+ ".value {"
+ " font-size: 12px;"
+ " color: green;"
+ "}"
+ "</style>"
+ "</head>"
+ "<body>"
+ "<h1>Orb of Deception</h1>"
+ "<table border=1>"
+ "<tr><td class='name'>Range</td><td class='value'>880</td></tr>"
+ "<tr><td class='name'>Cost</td><td class='value'>70/75/80/85/90 Mana</td></tr>"
+ "<tr><td class='name'>Cooldown</td><td class='value'>7</td></tr>"
+ "</table>"
+ "</body>"
+ "</html>";
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(null, new JLabel(text));
}
};
// Swing GUIs should be created and updated on the EDT
// http://docs.oracle.com/javase/tutorial/uiswing/concurrency
SwingUtilities.invokeLater(r);
}
}
关于java - 将字体和颜色设置为一个 JLabel 中包含的字符串的不同部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20583902/