java - Java Intelij Idea如何添加排水沟图标?
问题描述
在我的 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;
}
}
解决方案
推荐阅读
- jquery - 带有模板和搜索的 Select2 依赖下拉列表
- r - 传单输出未显示在仪表板正文中
- c# - 事件发生后将图像更改为 gif
- javascript - Google Analytics 或 Intercom 等 Snippets 使用哪种设计模式?
- php - 将多个数据集作为矩阵输入的 HTML/PHP 解决方案,如电子表格
- python - 如何在 conda 中安装包的扩展?
- elasticsearch - Kibana UI 无法为 v7.0.0 加载,并在 s390x 上出现错误“Kibana 未正确加载。检查服务器输出以获取更多信息”
- android - 这段代码有什么问题?为什么不工作,它告诉我“非法开始表达”,“预期;” 它指向我(视图 V))
- javascript - 如何在我的 YouTube MP4 和 MP3 下载器中编写 JavaScript 下载函数
- django - 如何在 Django 中使用过滤器迭代所有列值