Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Change color of IOConsoleOutputStream(Cannot change the color of the text written in a MessageConsole (with setColor))
Change color of IOConsoleOutputStream [message #1723242] Fri, 12 February 2016 16:41 Go to next message
Alexandre Honorat is currently offline Alexandre HonoratFriend
Messages: 8
Registered: February 2016
Junior Member
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 Smile
Re: Change color of IOConsoleOutputStream [message #1724259 is a reply to message #1723242] Mon, 22 February 2016 15:07 Go to previous message
Alexandre Honorat is currently offline Alexandre HonoratFriend
Messages: 8
Registered: February 2016
Junior Member
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.
Previous Topic:How to repair corrupted files in the $HOME/.p2 repo?
Next Topic:Contributing a custom delete handler to the project explorer context menu
Goto Forum:
  


Current Time: Tue Mar 19 09:26:54 GMT 2024

Powered by FUDForum. Page generated in 0.01920 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top