在 BlueJ/Java 中更改 system.out 字体和颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20929749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the system.out font and color in BlueJ/Java
提问by user3015246
Here is a very simple code
这是一个非常简单的代码
public class test
{
public static void main(String[] args)
{
System.out.println(" Hello ");
}
}
I am using a BlueJ IDE. What I want to do is make the color of the printed output red. And change the font to any custom made font - say Arial Unicode MS.
我正在使用 BlueJ IDE。我想要做的是使打印输出的颜色为红色。并将字体更改为任何自定义字体 - 例如 Arial Unicode MS。
Feel free to make changes to the code above or give detailed instructions if other things are required. Thanks in advance.
如果需要其他内容,请随意更改上面的代码或提供详细说明。提前致谢。
Edit:
编辑:
BlueJ seems to use a wordpad as a console. That is it Channels the output into wordpad/notepad. Does this mean I have to something else?
BlueJ 似乎使用写字板作为控制台。那就是将输出引导到写字板/记事本中。这是否意味着我必须做其他事情?
Or is it the bluej.defs file where I should try changing?
还是我应该尝试更改的 bluej.defs 文件?
回答by doomsdaymachine
You can change it to
你可以把它改成
System.err.println(" Hello ")
it will print in red color but "err" is usually used to print an error message as you may have already guessed.
它将以红色打印,但“err”通常用于打印您可能已经猜到的错误消息。
I don't think you can change console font colors and attributes from within the java code. However you can try fiddling around the setting in the BlueJ app and see if you can change it that way. In other words, it depends on the host thats displaying the output.
我认为您不能从 Java 代码中更改控制台字体颜色和属性。但是,您可以尝试摆弄 BlueJ 应用程序中的设置,看看是否可以更改它。换句话说,它取决于显示输出的主机。
回答by Matthew S.
Java does not support different colors in its console, for that matter it does not support text formatting at all. However, you can use an alternate console such as the Enigma Console.
Java 的控制台不支持不同的颜色,因此它根本不支持文本格式。但是,您可以使用备用控制台,例如Enigma 控制台。
With Enigma Consoleyou can simply, after adding the libraries to your project, do something like this:
使用Enigma Console,在将库添加到项目后,您可以简单地执行以下操作:
import java.awt.Color;
import enigma.console.*;
import enigma.core.Enigma;
public class test {
public static void main(String[] args) {
TextAttributes attrs = new TextAttributes(Color.BLUE, Color.WHITE);//Changes the color of background and text
s_console.setTextAttributes(attrs); //Sets the colors to the console
System.out.println("Hello World!"); //Default system println
}
private static final Console s_console; //Declare the Console
static
{
s_console = Enigma.getConsole("Hellow World!"); //Sets the console to the Enigma console, named "Hellow World!"
}
}
Hope this helps.
希望这可以帮助。
Your BlueJ preferences should look like this:
您的 BlueJ 首选项应如下所示:
If all works out, you should be able to do things like this:
如果一切顺利,你应该能够做这样的事情:
回答by Sam Miller
Or you can edit the stylesheets found in blueJ. For Windows, navigate to
C:\Program Files (x86)\BlueJ\lib\stylesheets
, then copy the css file called terminal. Paste it into C:\Users\name\bluej
. Edit the css file in your favorite ide (I prefer something that will preview a color on hover).
或者您可以编辑 blueJ 中的样式表。对于 Windows,导航到
C:\Program Files (x86)\BlueJ\lib\stylesheets
,然后复制名为 terminal.css 的 css 文件。将其粘贴到C:\Users\name\bluej
. 在你最喜欢的 ide 中编辑 css 文件(我更喜欢在悬停时预览颜色的东西)。
The css file here will override the previous file, so do notdelete the old file. If you mess up with your color changes, you want a backup.
这里的css文件会覆盖之前的文件,所以不要删除旧文件。如果你搞砸了你的颜色变化,你需要一个备份。
Aside: If you really want to have fun, edit the java-colors.css
file. That will edit the colors of the BlueJ editor. My current one (with Options->Preferences->Scope Highlighting set a little under halfway, accessible from the main bluej page) is:
旁白:如果您真的想玩得开心,请编辑java-colors.css
文件。这将编辑 BlueJ 编辑器的颜色。我当前的一个(选项->首选项->范围突出显示设置在一半以下,可从 bluej 主页面访问)是:
.token-keyword1 {
-fx-fill: #7A0F55;
}
.token-keyword2 {
-fx-fill: #AA4D00;
}
.token-keyword3 {
-fx-fill: #006699;
}
.token-comment-normal {
-fx-fill: #888;
}
.token-comment-javadoc {
-fx-fill: #06598F;
}
.token-comment-standout {
-fx-fill: #e527b3;
}
.token-primitive {
-fx-fill: #AA4D00;
}
.token-string-literal {
-fx-fill: #76B20E;
}
.token-label {
-fx-fill: #999999;
}
.token-invalid {
-fx-fill: #ff3300;
}
/* Default text colour */
.token-default {
-fx-fill: #000000;
}
.scope-colors {
-bj-background-color: #EEE;
-bj-class-color: #9EE047;
-bj-class-outer-color: #AAA;
-bj-class-inner-color: #AAA;
-bj-method-color: #E2D228;
-bj-method-outer-color: #F2A228;
-bj-selection-color: #378EA9;
-bj-selection-outer-color:#378EA9;
-bj-iteration-color: #D63938;
-bj-iteration-outer-color: #D63938;
-bj-breakpoint-overlay-color: rgba(200, 20, 20, 0.6);
-bj-step-overlay-color: rgba(20, 140, 20, 0.6);
}
.moe-step-mark-icon {
-fx-fill: rgb(20, 140, 20);
-fx-stroke: white;
}
.moe-editor-pane {
-fx-background-color: white;
-fx-highlight-fill: hsb(211, 50%, 90%);
}
.moe-find-result {
-rtfx-background-color: hsb(211, 20%, 99%);
}
.moe-editor-pane .caret {
-fx-stroke: rgb(255, 0, 100);
}#