aspose file tools*
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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How do I print in Color!" Watch "How do I print in Color!" New topic
Author

How do I print in Color!

Thomas Wren
Greenhorn

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!

Darrin


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

Joined: Oct 29, 2001
Posts: 8997
    
    9

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
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.
Darrin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I print in Color!