Java Intellij Idea 如何添加装订线图标?

标签 java intellij-idea plugins icons gutter

我在 IntelliJ idea 插件项目中渲染装订线图标时遇到问题。 problem

我想在行号旁边呈现装订线图标,但它只呈现小矩形。装订线图标路径已正确加载,装订线图标大小为 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;
    }
}

最佳答案

我相信您应该使用 com.intellij.codeInsight.daemon.LineMarkerProvider

参见 this postthis example

关于Java Intellij Idea 如何添加装订线图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60673377/

相关文章:

intellij-idea - 无法在 IntelliJ 中键入单括号或括号

c# - 如何在 AppDomain.Unload(domain) 之后删除 pluginassembly

C# 插件,是 Assembly.LoadFrom()... 类慢吗?

java - 我将一轮高尔夫球的每洞得分存储在数据库中。我想编写一个函数,对表中的该列求和并显示在 toast 中

java - Libgdx 表太小,无法填满视口(viewport)

java - 如何在 Hibernate-Spatial 和 Postgis 中持久保存 MultiPoligon 对象

gradle - 如何对导致 "No tests found for given includes"的@SpringBootTest 进行故障排除?

intellij-idea - 将 ANTLR 语法用于 IntelliJ IDEA 代码高亮插件?

android - Google Play 游戏服务 playerId 是静态的吗

java - 卡在刷新 gradle 项目。幕后发生了什么?