【问题标题】:Changing the system.out font and color in BlueJ/Java在 BlueJ/Java 中更改 system.out 字体和颜色
【发布时间】:2014-01-22 15:55:28
【问题描述】:

这是一个非常简单的代码

public class test
{
    public static void main(String[] args)
    {


    System.out.println("  Hello ");



    }
}

我正在使用 BlueJ IDE。 我想要做的是使打印输出的颜色变为红色。 并将字体更改为任何自定义字体 - 比如说 Arial Unicode MS。

如果需要其他操作,请随时更改上述代码或提供详细说明。 提前致谢。

编辑:

BlueJ 似乎使用写字板作为控制台。那就是将输出引导到写字板/记事本中。这是否意味着我必须做其他事情?

还是我应该尝试更改的 bluej.defs 文件?

【问题讨论】:

  • IDE 中的控制台可能不支持文本格式。 (查看文档了解详细信息,但几乎可以肯定没有。)

标签: java fonts colors system bluej


【解决方案1】:

或者您可以编辑 blueJ 中的样式表。对于 Windows,导航到 C:\Program Files (x86)\BlueJ\lib\stylesheets,然后复制名为终端的 css 文件。将其粘贴到C:\Users\name\bluej。在您最喜欢的 ide 中编辑 css 文件(我更喜欢在悬停时预览颜色的东西)。

这里的css文件会覆盖之前的文件,所以不要删除旧文件。如果你搞砸了你的颜色变化,你需要一个备份。


旁白:如果您真的想玩得开心,请编辑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);
}#

【讨论】:

    【解决方案2】:

    Java 在其控制台中不支持不同的颜色,因此它根本不支持文本格式。但是,您可以使用备用控制台,例如 Enigma Console

    使用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!"
        } 
    }
    

    希望这会有所帮助。

    您的 BlueJ 偏好应如下所示:

    如果一切顺利,您应该能够执行以下操作:

    【讨论】:

    • 如何使用这个 Enigma 控制台?我必须下载东西吗?如何整合它?
    • BlueJ 似乎使用写字板作为控制台。那就是将输出引导到写字板/记事本中。这是否意味着我必须做其他事情?
    • 从我上面列出的链接中下载并解压缩 Enigma 控制台后,将有一个名为“lib”的文件夹。在 BlueJ goto Preferences then libraries 中,从那里的 lib 文件夹中添加 jar 文件。之后,您可以运行我上面列出的代码,BlueJ 将像以前一样工作,但您可以修改颜色。
    • 我明白了。非常感谢您通知我。
    • 在它让你编译之前,在 BlueJ 中,重启虚拟机。让我知道这是否适合您。
    【解决方案3】:

    你可以改成

    System.err.println("   Hello ") 
    

    它将以红色打印,但“err”通常用于打印您可能已经猜到的错误消息。

    我认为您不能从 Java 代码中更改控制台字体颜色和属性。但是,您可以尝试在 BlueJ 应用程序中摆弄设置,看看是否可以这样更改。换句话说,它取决于显示输出的主机。

    【讨论】:

    • 是我应该尝试更改的 bluej.defs 文件吗?
    • 我刚刚下载并运行了 BlueJ 以在控制台上输出一些字符串,我认为这在 BlueJ 中是可能的。
    • 请告诉我如果你能弄明白的话。
    • 我认为这是不可能的,至少在 BlueJ 中是这样,但我肯定会让你知道。
    猜你喜欢
    • 2014-03-11
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 2020-01-15
    • 2013-11-14
    • 2014-01-19
    相关资源
    最近更新 更多