Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse PDE:StyleRange背景色在一秒钟后消失_Java_Eclipse_Eclipse Plugin_Background Color_Pde - Fatal编程技术网

Java Eclipse PDE:StyleRange背景色在一秒钟后消失

Java Eclipse PDE:StyleRange背景色在一秒钟后消失,java,eclipse,eclipse-plugin,background-color,pde,Java,Eclipse,Eclipse Plugin,Background Color,Pde,我目前正在开发一个Eclipse插件,为代码行以及大括号等添加颜色 我让一切都是动态工作的,也就是说,如果代码发生变化,线条颜色也会相应地更新 然而,一条线一旦着色,大约一秒钟后就会“重置”并删除所有颜色。 这是检查用户源代码是否已修改的事件侦听器 private void textModifiedListener() { for (IEditorPart editorPart : getCurrentEditorParts()) { editorText = e

我目前正在开发一个Eclipse插件,为代码行以及大括号等添加颜色

我让一切都是动态工作的,也就是说,如果代码发生变化,线条颜色也会相应地更新

然而,一条线一旦着色,大约一秒钟后就会“重置”并删除所有颜色。

这是检查用户源代码是否已修改的事件侦听器

    private void textModifiedListener() {
    for (IEditorPart editorPart : getCurrentEditorParts()) {
        editorText = editorPart.getAdapter(Control.class);
        if (editorText instanceof StyledText) {
            styledText = (StyledText) editorText;
            styledText.addModifyListener(new ModifyListener() {
                @Override
                public void modifyText(ModifyEvent event) {
                    //Source Code Modified.
                    Colour();
                }
            });
        }
    }
}
然后我给单个字符上色,如下所示:

    public void ColourCharacter(ColourObject colourOject, int characterIndex) {
    /* Given the colour and the character index, colour the given brace. */
    if (isColouringEnabled) {
        System.out.println("[ColourCode]:\tColourCharacter.");
        style = new StyleRange();
        style.start = characterIndex;
        style.length = 1;
        style.background = new Color(Display.getCurrent(), colourOject.getRed(), colourOject.getGreen(), colourOject.getBlue());
        if (editorText instanceof StyledText) {
            styledText.setStyleRange(style);
        }
    }
}
这些方法用于获得IEditorParts

    /* Obtain the current workbench window. */
public synchronized static IWorkbenchWindow getActiveWorkbenchWindow() {
    return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
}

/* Obtain the current editor reference. */
public synchronized static IEditorReference[] getCurrentEditorReferences() {
    return getActiveWorkbenchWindow().getActivePage().getEditorReferences();
}

/* Obtain the current editor parts. */
public synchronized List<IEditorPart> getCurrentEditorParts() {
    List<IEditorPart> editorParts = new ArrayList<IEditorPart>();
    for (IEditorReference editorReference : getCurrentEditorReferences()) {
        IEditorPart editor = editorReference.getEditor(true);
        if (editor != null) {
            editorParts.add(editor);
        }
    }
    return editorParts;
}
/*获取当前工作台窗口*/
公共同步静态IWorkbenchWindow getActiveWorkbenchWindow(){
返回平台ui.getWorkbench().getActiveWorkbenchWindow();
}
/*获取当前编辑器引用*/
公共同步静态IEditorReference[]getCurrentEditorReferences(){
返回getActiveWorkbenchWindow().getActivePage().getEditorReferences();
}
/*获取当前编辑器部件*/
公共同步列表getCurrentEditorParts(){
List editorParts=new ArrayList();
对于(IEditorReference-editorReference:getCurrentEditorReferences()){
IEditorPart editor=editorReference.getEditor(true);
如果(编辑器!=null){
editorParts.add(编辑器);
}
}
返回编辑部分;
}

我已经被这个问题困扰了一整天了。任何帮助都将不胜感激。

大多数现有编辑都有自己的文本样式设置系统。这通常使用JFace
SourceViewerConfiguration
对账器
呈现对账器
i呈现损坏管理器
i呈现修复器
等类

您不能像这样尝试覆盖样式。编辑器完全控制文本的样式,并将忽略您所做的任何更改。例如,
对账器
在后台运行,每半秒更新一次

您必须查看特定的编辑器,看看它提供了哪些功能来添加到其样式系统中


如果您只想标记错误和警告,可以使用
IMarker
界面。

大多数现有编辑器都有自己的文本样式设置系统。这通常使用JFace
SourceViewerConfiguration
对账器
呈现对账器
i呈现损坏管理器
i呈现修复器
等类

您不能像这样尝试覆盖样式。编辑器完全控制文本的样式,并将忽略您所做的任何更改。例如,
对账器
在后台运行,每半秒更新一次

您必须查看特定的编辑器,看看它提供了哪些功能来添加到其样式系统中


如果您只想标记错误和警告,可以使用
IMarker
界面。

大多数现有编辑器都有自己的文本样式设置系统。这通常使用JFace
SourceViewerConfiguration
对账器
呈现对账器
i呈现损坏管理器
i呈现修复器
等类

您不能像这样尝试覆盖样式。编辑器完全控制文本的样式,并将忽略您所做的任何更改。例如,
对账器
在后台运行,每半秒更新一次

您必须查看特定的编辑器,看看它提供了哪些功能来添加到其样式系统中


如果您只想标记错误和警告,可以使用
IMarker
界面。

大多数现有编辑器都有自己的文本样式设置系统。这通常使用JFace
SourceViewerConfiguration
对账器
呈现对账器
i呈现损坏管理器
i呈现修复器
等类

您不能像这样尝试覆盖样式。编辑器完全控制文本的样式,并将忽略您所做的任何更改。例如,
对账器
在后台运行,每半秒更新一次

您必须查看特定的编辑器,看看它提供了哪些功能来添加到其样式系统中

如果您只想标记错误和警告,则可以使用
IMarker
界面。

您可以改为使用。至少在Java编辑器中显示不同颜色的背景

您可能希望改用从。至少在Java编辑器中显示不同颜色的背景

您可能希望改用从。至少在Java编辑器中显示不同颜色的背景

您可能希望改用从。至少在Java编辑器中显示不同颜色的背景



您正在泄漏此代码中的
Color
对象。如果创建了
颜色
,则必须在创建完成后安排
处理它。您还应该为特定颜色重用
Color
对象,因为
Color
对象的数量可能会受到操作系统的限制。您看到的colorObject是我创建的对象。或者你指的是其他
Color
对象吗?
style.background=新颜色(..
谢谢。但是,我仍然有同样的问题,颜色在大约一秒钟后消失:/这并不能解决这个问题,我只是指出代码中的一个缺陷(这就是为什么它是一个注释)。您正在泄漏此代码中的
Color
对象。如果您创建了
Color
,则必须在创建后安排
dispose
该对象。您还应为特定对象重新使用
Color
对象