Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: How to make console output bold

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to make console output bold

    The program I am creating displays the output into the console and prints out tables. I want the header of these said tables to be bold, how can I do that?

    here is what I want bold:

     
    System.out.printf("%100s\n", "January");

    Just the word January.


  2. #2
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: How to make console output bold

    Quote Originally Posted by ColeTrain View Post
    ... I want the header of these said tables to be bold...how...?
    That depends...

    I'll show what works for me running from a command prompt in a gnome-terminal window on my Centos 5.8 Linux system. My "normal" display mode is with the default white-background system terminal. (If you want to understand what is in my Strings, you can look up "ANSI Escape Sequences")

    public class Z {
        public static void main(String [] args) {
            String boldGrayLine = "\033[1mThis is a BOLD line\033[0m";
            String setBold = "\033[1mThis keeps it bold.";
            String normalLine = "This is a normal (default) line";
            String setNormal = "\033[0mThis un-bolds it.";
            System.out.println(normalLine);
            System.out.println(boldGrayLine);
            System.out.println(normalLine);
            System.out.println(setBold);
            System.out.println(normalLine);
            System.out.println(setNormal);
            System.out.println(normalLine);
        }
    }

    I'll try to show what the output looks like on my system

    This is a normal (default) line
    This is a BOLD line
    This is a normal (default) line
    This keeps it bold.
    This is a normal (default) line
    This un-bolds it.
    This is a normal (default) line


    Now, if your system and command window are not implemented to respond to ANSI escape sequences, you will have to try other approaches.

    Here is an example: A Splash of text color with your Java There are other ways that may be more suitable for your purposes.

    Now, I haven't tried this for the following reason:

    As a newcomer to Java, I don't think it's worth my time trying to "dress up" console output for my programs. I just print the text and try to learn how to write Java to solve various problems that I am interested in.

    I mean, if I think the target audience for my code wants something that looks "nice" (that is, if I want something to look "better" than plain old text), I try to learn enough of the graphics API (awt and/or swing) to get that particular output to be presentable.

    But maybe that's just me. I'm funny that way.


    Cheers!

    Z
    Last edited by Zaphod_b; October 14th, 2012 at 01:47 PM.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to make console output bold

    Well the thing is this is for a class I am taking and the teacher wants it bold, yet he didn't teach us how to bold and I can't find it in the book anywhere. Thanks for the help.

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to make console output bold

    When I use that format it is actually turning my text gray and not bolding it...

     String bold= "\033[1mJanuary\033[0m";
            System.out.printf("%100s\n", bold);

  5. #5
    Member
    Join Date
    Jun 2012
    Location
    Left Coast, USA
    Posts
    451
    My Mood
    Mellow
    Thanks
    1
    Thanked 97 Times in 88 Posts

    Default Re: How to make console output bold

    What operating system are you using?

    What is the color of the background of your window? I mean, the sequences that I showed are for "light gray" and "dark gray." (I think.) So maybe you want "bright white" and "un-bright white" to show up as "bold" and "not bold" for your background. Or some such thing.

    Which brings me to my final question:

    Have you looked for any reference material on ANSI Escape Sequences. The fact that your system responds to the sequence is a good sign. Some systems just echo the [1m and 0[m stuff as those characters on the screen and don't change the display characteristics at all.

    Cheers!

    Z
    Last edited by Zaphod_b; October 14th, 2012 at 05:15 PM.

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to make console output bold

    I am programming in NetBeans. The default console output is normal black. All i need is to bold it.

  7. #7
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How to make console output bold

    It's worth noting that NetBeans is going to react differently then your console. Try exporting it to a runnable jar and test it, that should give you an idea of what it actually looks like.

Similar Threads

  1. How do you make a console program a .jar in Eclipse?
    By Programmer142 in forum Java Theory & Questions
    Replies: 9
    Last Post: January 13th, 2012, 12:13 AM
  2. Having problems with output to console....help!
    By toppcon in forum What's Wrong With My Code?
    Replies: 21
    Last Post: July 13th, 2011, 06:38 PM
  3. Make some text bold, some NOT bold. JTextField
    By danny_felipe in forum Java Theory & Questions
    Replies: 2
    Last Post: May 27th, 2010, 06:44 PM
  4. Changing output from console to .html
    By RSYR in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: December 10th, 2009, 07:55 PM
  5. printing output to console & to a text file at the same time...
    By prasanna in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: August 26th, 2009, 03:43 AM