簡體   English   中英

Java Intelij Idea 如何添加裝訂線圖標?

[英]Java Intelij Idea how to add gutter icon?

在我的 IntelliJ 創意插件項目中,我在渲染裝訂線圖標時遇到問題。 問題

我想在行號旁邊呈現裝訂線圖標,但它只呈現小矩形。 裝訂線圖標路徑已正確加載,裝訂線圖標大小為 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

請參閱此帖子此示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM