问题
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.
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?
Or is it the bluej.defs file where I should try changing?
回答1:
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.
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.
回答2:
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.
With Enigma Console you can simply, after adding the libraries to your project, do something like this:
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:
If all works out, you should be able to do things like this:
回答3:
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).
The css file here will override the previous file, so do not delete the old file. If you mess up with your color changes, you want a backup.
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:
.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);
}#
来源:https://stackoverflow.com/questions/20929749/changing-the-system-out-font-and-color-in-bluej-java