有没有办法可以更改文本的打印颜色?
Is there a way i can change the print out color of my Text?
For Example
String text = "sample";
System.out.println(text);
I want the text to appear in color RED.Tried java.awt but a bit confusing for me.
您可以更改 ANSI 默认颜色。
假设您有 2 种颜色
String Green = "\u001B[32m";
String Defauld = "\u001B[0m";
一串,
字串字="Hello World";
和打印代码
System.out.print(Green + word + Defauld + "the end .");
它在 Green.I 中打印不知道这是否适用于我的 Linux
中的每个 system.Works
PS:我现在无法访问电脑,你可以在 windows 中尝试以下操作吗??
String Green = "\x1b[31m;
String Defauld = "\x1b[0m";
另一种解决方案是使用 JCDP(Java 彩色调试打印机),它适用于 Windows 和 Linux。来自这里的回复 .
GitHub: https://github.com/dialex/JCDP#downloads
我刚刚在 Windows 7 上尝试了 IntelliJ 中的示例,结果如下:
如果您使用的是 eclipse...您可以使用
System.err.println("...");
这将在 eclipse 控制台中以红色打印。
For Example
String text = "sample";
System.out.println(text);
I want the text to appear in color RED.Tried java.awt but a bit confusing for me.
您可以更改 ANSI 默认颜色。 假设您有 2 种颜色
String Green = "\u001B[32m";
String Defauld = "\u001B[0m";
一串,
字串字="Hello World";
和打印代码
System.out.print(Green + word + Defauld + "the end .");
它在 Green.I 中打印不知道这是否适用于我的 Linux
中的每个 system.WorksPS:我现在无法访问电脑,你可以在 windows 中尝试以下操作吗??
String Green = "\x1b[31m;
String Defauld = "\x1b[0m";
另一种解决方案是使用 JCDP(Java 彩色调试打印机),它适用于 Windows 和 Linux。来自这里的回复 .
GitHub: https://github.com/dialex/JCDP#downloads
我刚刚在 Windows 7 上尝试了 IntelliJ 中的示例,结果如下:
如果您使用的是 eclipse...您可以使用
System.err.println("...");
这将在 eclipse 控制台中以红色打印。