Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Thanked 0 Times in 0 Posts

    Java HelloWorld set color

    How would I set a color to the text HelloWorld. My simpe script:

    class HelloWorld {
    public static void main(String[] args) { 
     System.out.println("Hello world!");

  2. #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,668 Times in 2,637 Posts
    I've never done colours in the console through java before. Though I think you could *probably* to it, it wouldn't be worth while, and it defeats the purpose of crossplatform independence. The AWT should have something that lets you hook into the OS commands, but I don't know if they are accessible for the programmer to manipulate.
    It would be easier to create a GUI that emulates a console window and apply text color to that. You can make it look and feel like a console window, but it would be cross platform which rocks.

    The problem with the consoles is that colours are platform dependent. Even with C you'd need to inspect you're environment, import the correct libraries and issue the proper commands.
    Consoles are such a pain, but as long as you're happy with the default background and colours that you use, they are way faster than a gui ever could be.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  3. #3
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Ontario, Canada
    Thanked 20 Times in 20 Posts
    A quick google search led me to this page http://www.javaworld.com/javaworld/j...0-console.html

    It seems to do a good job of explaining why it's not possible to do this in the "traditional" sense, and provides a couple examples of using other libraries to "mimic" console text colour if it's something you really need.

    Personally, I don't feel that it's worth the effort for most cases.

  4. #4
    New to the CF scene
    Join Date
    Nov 2008
    Thanked 0 Times in 0 Posts
    You can try some of ncurses library for java, but it will work under unix OS's and I'm not sure if there are ncurses library under win.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts