如何在 java 中使用多种颜色的文本?

How to have text with multiple colours in java?

我正在尝试制作一个拼写检查器,结果应该是 window,其中突出显示了拼写错误的单词。文本存储在一个数组中(当前),缺失单词的 id 在另一个数组中排序。我该怎么做?

编辑:这是我目前所拥有的,但它似乎不起作用。

int l = 0;
String txtstring = "<html>";
for(int i = 0; i<textArray.length ; i++){
    if(placement[l].equals(i)){
        l++;
        txtstring = txtstring + "<font color = red>" + textArray[i] + "</font>" + " ";
     } else {
        txtstring = txtstring + textArray[i] + " ";
    }
}
txtstring = txtstring + "</html>";

Copy-pasting OP 的最后编辑:

改变

if(placement[l].equals(i)){

对于

if(Integer.parseInt(placement[l])==i){

成功了,结果是这样的:

int l = 0;
String txtstring = "<html>";
for(int i = 0; i<textArray.length ; i++){
    if(Integer.parseInt(placement[l])==i){
        l++;
        txtstring = txtstring + "<font color = red>" + textArray[i] + "</font>" + " ";
     } else {
        txtstring = txtstring + textArray[i] + " ";
    }
}
txtstring = txtstring + "</html>";