我试图突出显示客户端发送的修复消息的错误。 但是,这样做时不会遵循此算法。如果修复消息中只有一个字符串出现错误,它将突出显示整个字符串,否则它将不会突出显示。 基本上我要问的是如何突出显示多个部分,而不是在出现错误时突出显示整个输出?
例如: 我得到的错误
no error - unhighlighted
error - highlighted
no error - highlighted
no error - highlighted
no error - highlighted
error - highlighted
我想要的是什么:
no error - unhighlighted
error - highlighted
no error - unhighlighted
no error - unhighlighted
no error - unhighlighted
error - highlighted
问题区域
if(outputLine.equals("No errors")) {
tfCSVLine.append(outputLine+"\n\n\n");
lengthH += (inputLine+"\n\n\n").length();
}
else {
tfCSVLine.append(outputLine+"\n\n\n");
int pos = inputLine.indexOf(inputLine, 0);
int len = lengthH;
lengthH += (inputLine+"\n\n\n").length();
h.addHighlight(len, lengthH+(inputLine+"\n\n\n").length(),
DefaultHighlighter.DefaultPainter);
}
程序
Highlighter h = tfFIXMsg.getHighlighter();
try {
int lengthH = 0;
while ((inputLine = in.readLine()) != null) {
System.out.println ("Server: " + inputLine);
tfFIXMsg.append( inputLine + "\n\n\n");
if (inputLine.trim().equals("Bye.")) {
System.out.println("Exit program");
break;
}
Scanner input1 = new Scanner(new File(csvName));
Scanner input2 = new Scanner(new File(csvName));
Scanner input3 = new Scanner(new File(csvName));
Scanner input4 = new Scanner(new File(csvName));
String csvline = getCsvLineVal(getLocation34CSV(
getTag34Value(Tag34Location(getTagCSV(parseFixMsg(
inputLine ,inputLine))), getValueCSV( parseFixMsg(
inputLine ,inputLine))), getVal34(input1,input2)),
getCSVLine( input3, input4) );
outputLine = compareClientFixCSV( getTagCSV(parseFixMsg(
inputLine ,inputLine)), getValueCSV(parseFixMsg(
inputLine ,inputLine)), getCSVTag(csvline), getCSVValue(csvline));
out.println(outputLine);
if(outputLine.equals("No errors")) {
tfCSVLine.append(outputLine+"\n\n\n");
lengthH += (inputLine+"\n\n\n").length();
}
else {
tfCSVLine.append(outputLine+"\n\n\n");
int pos = inputLine.indexOf(inputLine, 0);
int len = lengthH;
lengthH += (inputLine+"\n\n\n").length();
h.addHighlight(len, lengthH+(inputLine+"\n\n\n").length(),
DefaultHighlighter.DefaultPainter);
}
input1.close();
input2.close();
input3.close();
input4.close();
}
答案 0 :(得分:2)
您要将(inputLine+"\n\n\n").length()
两次添加到长度。你应该这样做一次吗?此外,当'else'块执行时,看起来长度是否正确初始化?