Change color of IOConsoleOutputStream [message #1723242] |
Fri, 12 February 2016 11:41  |
Eclipse User |
|
|
|
Hi everybody,
I want to print some text in a MessageConsole and I would like to color some parts of it.
I have tried to use the setColor method to change the MessageConsoleStream but it seems to not work. I guess my problem is more related to the usage of Device and Color, but I am not sure.
Here is the code I use to write to the console:
MessageConsoleStream mcs = mc.newMessageStream();
Color currentClr = mcs.getColor();
RGB red = new RGB(255, 0, 0);
//Device device = currentClr.getDevice();
Device device = Display.getDefault();
Color warningColor = new Color(device, red);
mcs.setColor(warningColor);
mcs.println("This text should be colored in red, right? But it isn't.");
mcs.setColor(currentClr);
As you can see I have tried two ways to get a device to pass to the Color constructor. The commented one throws a null pointer exception. And the current one prints text in black. Besides I don't need fancy colors, so if some basic ones (as red, yellow, etc) are predefined it is perfect for me.
Any ideas ? Thanks 
|
|
|
Re: Change color of IOConsoleOutputStream [message #1724259 is a reply to message #1723242] |
Mon, 22 February 2016 10:07  |
Eclipse User |
|
|
|
Hi,
ok I found why my text wasn't printed in red. Actually it was ... but only for a couple of micro seconds !
When setting the stream color, even already printed message with this stream are redraw with the new color. So my code was actually printing the text in red and immediately after that reprinting it in black (because of the setColor to the old value).
This thread proposes to create one stream per color as a solution.
|
|
|
Powered by
FUDForum. Page generated in 0.03597 seconds