Changing the system.out font and color in BlueJ/Java

23,537

Solution 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.

Solution 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: BlueJ Preferences

If all works out, you should be able to do things like this: If all works out, you should be able to do things like this:

Share:
23,537
user3015246
Author by

user3015246

Updated on July 07, 2022

Comments

  • user3015246
    user3015246 almost 2 years

    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?

    • Admin
      Admin over 10 years
      The console in your IDE probably doesn't support text formatting. (Check the documentation for details, but it almost certainly doesn't.)
  • user3015246
    user3015246 over 10 years
    is it the bluej.defs file where I should try changing?
  • doomsdaymachine
    doomsdaymachine over 10 years
    i just downloaded and ran BlueJ to output some string on the console and I think its possible in BlueJ.
  • user3015246
    user3015246 over 10 years
    How do I use this Enigma console? Do I have to download stuff? How to I integrate it?
  • user3015246
    user3015246 over 10 years
    BlueJ seems to use a wordpad as a console. That is it Channels the output into wordpad/notepad. Dos this mean I have to something else?
  • user3015246
    user3015246 over 10 years
    Please tell me how if you can figure it out.
  • doomsdaymachine
    doomsdaymachine over 10 years
    I don't think its possible, at least in BlueJ, but I'll definitely let you know otherwise.
  • Matthew S.
    Matthew S. over 10 years
    Once you download and unzip the Enigma console from the link I listed above, there will be a folder in called "lib". In BlueJ goto Preferences then libraries, add the jar files from the lib folder there. After that you can run the code I listed above, and BlueJ will work exactly as before, but give you the ability to modify the color.
  • user3015246
    user3015246 over 10 years
    I see. Thanks a lot for informing me.
  • Matthew S.
    Matthew S. over 10 years
    Before it will let you compile, in BlueJ, restart the virtual machine. Let me know if this works out for you.
  • user3015246
    user3015246 over 10 years
    How do you restart the virtual machine?
  • Matthew S.
    Matthew S. over 10 years
    Right-click the grey or red bar on the bottom left of the screen and click restart virtual machine, or go to tools then restart virtual machine
  • user3015246
    user3015246 over 10 years
    Thanks. You mean the "reset" virtual machine thing? Ok. Thanks a lot for the edit. I will try it out. But you may have to wait 2-3 days before I give the feedback. I want to test it when I am a bit free. Also, I first want to try if Ican do anything with normal blueJ console.