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.
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.
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.
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.
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.
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.
I am programming in NetBeans. The default console output is normal black. All i need is to bold it.
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.