以编程方式更改 Netbeans 内部的颜色?
Changing the colors inside of Netbeans programatically?
所以我今天想到了一个 java 程序在我的 PC 后台运行并定期检查系统时间的想法,当我注意到季节变化时(冬天,秋天) , 夏天, Spring), 我会更改 IDE 的所有颜色(关键字和评论和背景)以适应季节的颜色。不幸的是,我找不到这些信息在文件中的存储位置。有谁知道它可能在哪里或者这是否可能?谢谢!
是的,这是可能的!!!
- 运行时间选项
- 使用配置文件
- 使用 netbeans 库
1。 运行 时间选项
如果你喜欢'MetalLookAndFeel & fontsize 14, 运行 below command
netbeans --laf javax.swing.plaf.metal.MetalLookAndFeel --fontsize 14
您可以从此 link → Netbeans themes 安装主题列表。您可以根据您的选择以编程方式启动不同的主题。
2。使用配置文件
这可以通过更新位于以下位置 ${nb-install}/etc/netbeans.conf
的 netbeans.conf
文件来实现
例如:
C:\Program Files\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
- 金属 - javax.swing.plaf.metal.MetalLookAndFeel
- GTK - com.sun.java.swing.plaf.gtk.GTKLookAndFeel
- 水色 - apple.laf.AquaLookAndFeel
此外,您还可以配置其他参数。
此处列出的所有启动参数 → Startup Parameters
3。使用 netbeans 库
您可能对此更感兴趣。
完整的 netbeans API → netbeans Api
对应的Jar文件→jar files
`org.netbeans.api.editor.settings.FontColorSettings` will be used to change the font settings which include keywords, syntax, background, foreground etc.
一个小例子供大家参考
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();
}
}
}
所以我今天想到了一个 java 程序在我的 PC 后台运行并定期检查系统时间的想法,当我注意到季节变化时(冬天,秋天) , 夏天, Spring), 我会更改 IDE 的所有颜色(关键字和评论和背景)以适应季节的颜色。不幸的是,我找不到这些信息在文件中的存储位置。有谁知道它可能在哪里或者这是否可能?谢谢!
是的,这是可能的!!!
- 运行时间选项
- 使用配置文件
- 使用 netbeans 库
1。 运行 时间选项
如果你喜欢'MetalLookAndFeel & fontsize 14, 运行 below command
netbeans --laf javax.swing.plaf.metal.MetalLookAndFeel --fontsize 14
您可以从此 link → Netbeans themes 安装主题列表。您可以根据您的选择以编程方式启动不同的主题。
2。使用配置文件
这可以通过更新位于以下位置 ${nb-install}/etc/netbeans.conf
的 netbeans.conf
文件来实现
例如:
C:\Program Files\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
- 金属 - javax.swing.plaf.metal.MetalLookAndFeel
- GTK - com.sun.java.swing.plaf.gtk.GTKLookAndFeel
- 水色 - apple.laf.AquaLookAndFeel
此外,您还可以配置其他参数。 此处列出的所有启动参数 → Startup Parameters
3。使用 netbeans 库
您可能对此更感兴趣。 完整的 netbeans API → netbeans Api 对应的Jar文件→jar files
`org.netbeans.api.editor.settings.FontColorSettings` will be used to change the font settings which include keywords, syntax, background, foreground etc.
一个小例子供大家参考
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();
}
}
}