• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I print in Color!

 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say I have a line that is going to be printed to the user. The line prompts the user to give him the choice rather to run the program or not.

The code would look like this;

System.out.println(" If you want to run the program again press 1. If not, then press 0.");

how can i make this Show up in color for a linux system? or in a pop up box.?
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Thomas!

If you want to print in color to the shell the user is using, thats not possible to specify from Java, it is controlled by the xterm the user is running.
If you are asking the question in a pop up, say in a JDialog, just set the foreground color of the JLabel to the desired color.

Hope that helps!

Darrin
 
Joe Ess
Bartender
Pie
Posts: 9257
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ANSI escape codes should work under Linux. Have a look at the code here
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some do! (ASCI escape codes)
Unfortunately, the color codes don't. Just to be sure, I tried them with xterm, konsole, and gnome-terminal. The clear screen, normal, bold, and reverse codes work just fine, but the color codes seem to be ignored.

Thanks for the hint Joe! I never thought to try those!

Darrin
 
Darrin Cartwright
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The color codes don't work.....
Because I was formatting them wrong! Oops!
Now they work fine.
Darrin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic