在我的 IntelliJ idea 插件项目中,我在渲染排水沟图标时遇到问题。
我想在行号旁边呈现装订线图标,但它只呈现小矩形。装订线图标路径已正确加载,装订线图标大小为 12x12px,格式为 png。你能帮助我吗?
我的代码:
public static void addLineHighlight(Document document, int lineNumber,
String text) {
Icon highlightIcon = IconLoader.getIcon("META-INF/fail.png");
addGutterIcon(getRangeHighlighter(document, lineNumber), highlightIcon, text);
}
@NotNull
private static RangeHighlighter getRangeHighlighter(Document document, int lineNumber) {
MarkupModel markupModel = getMarkupModel(document);
TextAttributes textAttributes = getTextAttributes();
RangeHighlighter highlighter;
highlighter = markupModel.addLineHighlighter(lineNumber, 66 , textAttributes);
return highlighter;
}
private static void addGutterIcon(@NotNull RangeHighlighter highlighter, Icon icon, String text) {
highlighter.setGutterIconRenderer(new GutterIconRenderer() {
@Override
public boolean equals(Object obj) {
return false;
}
@Override
public int hashCode() {
return 0;
}
@NotNull
@Override
public Icon getIcon() {
return icon;
}
});
}
private static MarkupModel getMarkupModel(Document document) {
return DocumentMarkupModel.forDocument(document, TestSingleton.getInstance().getProject(), true);
}
@NotNull
private static TextAttributes getTextAttributes() {
TextAttributes textAttributes = null;
textAttributes = new TextAttributes();
textAttributes.setBackgroundColor(JBColor.RED);
textAttributes.setErrorStripeColor(JBColor.RED);
return textAttributes;
}
}