アクティブな行の箇条書きの背景を強調表示しようとしています。私は使用しています
int activeLine = styledText.getLineAtOffset(styledText.getCaretOffset());
現在アクティブなようなものを取得します。Enterキーを押して新しい行を取得する場合を除いて、これは機能するようです。
getCaretOffset は 35 を返し、getCharCount は 36 を返します。
ただし、最後の行をクリックすると (今のところ、クリック時に redraw() を呼び出します)、行が正しく強調表示され、getCaretOffset は 36 を返します。
ここに関連するコードがあります
public void lineGetStyle(LineStyleEvent event) {
// Set the line number
int activeLine = styledText.getLineAtOffset(styledText.getCaretOffset());
System.out.println("Offset " + styledText.getCaretOffset() + " max " + styledText.getCharCount());
int currentLine = styledText.getLineAtOffset(event.lineOffset);
event.bulletIndex = currentLine;
// Set the style, 12 pixles wide for each digit
StyleRange style = new StyleRange();
style.metrics = new GlyphMetrics(0, 0, 36);
if (activeLine == currentLine) {
style.background = highlightedLine;
if (curActiveLine != activeLine){
System.out.println("ActiveLine " + activeLine + " old " + curActiveLine);
int redrawLine = curActiveLine;
curActiveLine = activeLine;
styledText.redraw(0, styledText.getLinePixel(redrawLine), 36, styledText.getLineHeight(),true);
}
}
style.foreground = mainBackground;
// Create and set the bullet
event.bullet = new Bullet(ST.BULLET_NUMBER, style);
event.styles = matchKeywords(event);
}