通过编程更改Netbeans内部的颜色?

通过编程更改Netbeans内部的颜色?,netbeans,ide,config,Netbeans,Ide,Config,所以我今天想到了一个主意,在我的电脑上有一个java程序在后台运行,定期检查系统时间,当我注意到季节变化(冬季、秋季、夏季、春季)时,我会改变IDE的所有颜色(关键字、注释和背景),以适应季节的颜色。不幸的是,我找不到该信息存储在文件中的位置。有没有人知道它可能在哪里,或者这是否可能?谢谢 是的,这是可能的!!! 运行时选项 使用配置文件 使用netbeans库 1.运行时选项 如果您想使用“MetalLookAndFeel&fontsize 14”,请运行下面的命令 netbeans --la

所以我今天想到了一个主意,在我的电脑上有一个java程序在后台运行,定期检查系统时间,当我注意到季节变化(冬季、秋季、夏季、春季)时,我会改变IDE的所有颜色(关键字、注释和背景),以适应季节的颜色。不幸的是,我找不到该信息存储在文件中的位置。有没有人知道它可能在哪里,或者这是否可能?谢谢

是的,这是可能的!!!
  • 运行时选项
  • 使用配置文件
  • 使用netbeans库
  • 1.运行时选项 如果您想使用“MetalLookAndFeel&fontsize 14”,请运行下面的命令

    netbeans --laf javax.swing.plaf.metal.MetalLookAndFeel --fontsize 14
    
    您可以从此链接安装主题列表→ . 您可以根据自己的选择以编程方式启动不同的主题

    2.使用配置文件 这可以通过更新位于下面位置
    ${nb install}/etc/netbeans.conf
    例如:

    C:\ProgramFiles\NetBeans 8.1\etc\NetBeans.conf

    以编程方式使用所需的主题和字体大小更新conf文件。 例如:

    netbeans_default_options=“-J-client-J-Xss2m-J-Xms32m -J-Dapple.laf.useScreenMenuBar=true-J-Dapple.awt.graphics.UseQuartz=true-J-Dsun.java2d.noddraw=true-J-Dsun.java2d.dpiaware=true-J-Dsun.zip.disableMemoryMapping=true”

    您可以更新多个外观选项

    • Windows-com.sun.java.swing.plaf.Windows.WindowsLookAndFeel
    • Metal-javax.swing.plaf.Metal.MetalLookAndFeel
    • GTK-com.sun.java.swing.plaf.GTK.GTKLookAndFeel
    • Aqua-apple.laf.AquaLookAndFeel
    此外,还可以配置其他参数。 此处列出了所有启动参数→

    3.使用netbeans库 你可能对这个更感兴趣。 完整netbeans API→ 对应的Jar文件→

    一个小例子供你参考

    public void updateColors() {
        EditorUI editorUI = Utilities.getEditorUI(textComponent);
        if (editorUI == null) {
            return;
        }
        String mimeType = NbEditorUtilities.getMimeType(textComponent);
        FontColorSettings fontColorSettings = MimeLookup.getLookup(MimePath.get(mimeType)).lookup(FontColorSettings.class);
        Coloring lineColoring = Coloring.fromAttributeSet(fontColorSettings.getFontColors(FontColorNames.LINE_NUMBER_COLORING));
        Coloring defaultColoring = Coloring.fromAttributeSet(fontColorSettings.getFontColors(FontColorNames.DEFAULT_COLORING));
    
        if (lineColoring == null) {
            return;
        }
    
        // use the same color as GlyphGutter
        final Color backColor = lineColoring.getBackColor();
        // set to white by o.n.swing.plaf/src/org/netbeans/swing/plaf/aqua/AquaLFCustoms
        if (org.openide.util.Utilities.isMac()) {
            backgroundColor = backColor;
        } else {
            backgroundColor = UIManager.getColor("NbEditorGlyphGutter.background"); //NOI18N
        }
        if (null == backgroundColor) {
            if (backColor != null) {
                backgroundColor = backColor;
            } else {
                backgroundColor = defaultColoring.getBackColor();
            }
        }
    }
    

    谢谢你!我尝试导入您建议的Netbeans API包,但默认情况下它显然不存在。我在网上查了一下下载,但找不到。知道我怎么加吗?它在Netbeans中的某个地方吗?谢谢Jar文件下载链接→ , 我也更新了我的答案,以备将来参考。
    public void updateColors() {
        EditorUI editorUI = Utilities.getEditorUI(textComponent);
        if (editorUI == null) {
            return;
        }
        String mimeType = NbEditorUtilities.getMimeType(textComponent);
        FontColorSettings fontColorSettings = MimeLookup.getLookup(MimePath.get(mimeType)).lookup(FontColorSettings.class);
        Coloring lineColoring = Coloring.fromAttributeSet(fontColorSettings.getFontColors(FontColorNames.LINE_NUMBER_COLORING));
        Coloring defaultColoring = Coloring.fromAttributeSet(fontColorSettings.getFontColors(FontColorNames.DEFAULT_COLORING));
    
        if (lineColoring == null) {
            return;
        }
    
        // use the same color as GlyphGutter
        final Color backColor = lineColoring.getBackColor();
        // set to white by o.n.swing.plaf/src/org/netbeans/swing/plaf/aqua/AquaLFCustoms
        if (org.openide.util.Utilities.isMac()) {
            backgroundColor = backColor;
        } else {
            backgroundColor = UIManager.getColor("NbEditorGlyphGutter.background"); //NOI18N
        }
        if (null == backgroundColor) {
            if (backColor != null) {
                backgroundColor = backColor;
            } else {
                backgroundColor = defaultColoring.getBackColor();
            }
        }
    }