wood burning stoves
The moose likes Java in General and the fly likes How do I print in Color! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I print in Color!" Watch "How do I print in Color!" New topic

How do I print in Color!

Thomas Wren

Joined: Nov 06, 2006
Posts: 11
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

Joined: Dec 27, 2002
Posts: 107
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!


Life is good on the Ponderosa,<br />but mind where you step.
Joe Ess

Joined: Oct 29, 2001
Posts: 9152

ANSI escape codes should work under Linux. Have a look at the code here

[How To Ask Questions On JavaRanch]
Darrin Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
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 Cartwright
Ranch Hand

Joined: Dec 27, 2002
Posts: 107
The color codes don't work.....
Because I was formatting them wrong! Oops!
Now they work fine.
I agree. Here's the link: http://aspose.com/file-tools
subject: How do I print in Color!
It's not a secret anymore!