| Author |
Can toString print in color?
|
David Tschoepe
Greenhorn
Joined: Feb 13, 2005
Posts: 1
|
|
Hi, I want to spruce up an assignment for class and was wondering if there was a way to make the output from toString to the console display in some color other than white? Thanks, David
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
First of all, toString() doesn't print anything. It simply returns a String representation of the object it is called on. However, OutputStreams and Writers from the java.io package DO print. There may be a way to print in color, if your terminal supports ANSI codes. However, this would take some sophisticated manipulation of the OutputStream. Even more importantly, it seems to me that any attempt to do this would be system dependent. Anyway, that's my long-winded way of saying that I don't know how to do it. Perhaps I've given you some ideas to think on or keywords you can google for. Layne
|
Java API Documentation
The Java Tutorial
|
 |
M Beck
Ranch Hand
Joined: Jan 14, 2005
Posts: 323
|
|
google for curses. it's a time-honored Unix library meant to alleviate some of the platform-dependency of this sort of thing; basically, it's an abstraction library meant to translate between platform-independent, higher-level notions (even some text-mode "GUI" widgets!) and whatever the machine-dependent lower layers need. as far as i can tell (mostly from this JavaWorld article) you'll likely still need to use JNI to access a curses implementation. but at least you won't have to hardcode ANSI escape sequences in your code, and curses has been ported to Windows, so it's quite widely available.
|
 |
Jeroen Wenting
Ranch Hand
Joined: Oct 12, 2000
Posts: 5093
|
|
curses may have been ported to Windows but it's not generally available on Windows machines. The results of relying on it are therefore unpredictable.
|
42
|
 |
M Beck
Ranch Hand
Joined: Jan 14, 2005
Posts: 323
|
|
|
unless you choose to distribute it with your application. granted that this will bloat your jar files somewhat, but at least it will save you the bother and headache of hand-coding escape sequences.
|
 |
 |
|
|
subject: Can toString print in color?
|
|
|