Search code examples
javaintellij-ideaintellij-plugin

How to set background color of PsiFileNode or its child


How to set background color of PsiFileNode or its child? I know how to change PsiFileNode fileName foreground

    public class MarkedFile extends PsiFileNode {
    private Color backgroundColor;

    public MarkedFile(Project project, @NotNull PsiFile value, ViewSettings viewSettings, Color backgroundColor) {
        super(project, value, viewSettings);
        this.backgroundColor = backgroundColor;
    }

    public Color getBackgroundColor() {
        return backgroundColor;
    }

    public void setBackgroundColor(Color backgroundColor) {
        this.backgroundColor = backgroundColor;
    }

    @NotNull
    @Override
    protected PresentationData createPresentation() {
        PresentationData presentationData = super.createPresentation();
        presentationData.setForcedTextForeground(backgroundColor);
        return presentationData;
    }
  }

But how to set background color of file as we can see it in "target" or "out" java directories


Solution

  • You can control the background color of files in the project tree and tabs via EditorTabColorProvider.EP_NAME extension point. Override getProjectViewColor to highlight a file in the project tree.