Lennart van Ham wrote:Can someone tell me how to change the color of an output element in Eclipse? Can't seem to find it anywhere on the internet.
For example, a response to my question 'What color do you want?' could be 'red'. I added an if-statement, which states if input = red, start using a red colored 'X' as string for further output.
How do I obtain the color red for my X??
Or isn't it possible changing the color of output elements?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Lennart van Ham wrote:I added an if-statement, which states if input = red,
Winston Gutkowski wrote:Well, Java has a Color class (java.awt.Color (←click)), and that class has a constant called Color.RED.
Winston Gutkowski wrote:And I presume you want a solution that will work anywhere, not just in Eclipse ... or is this something specific to Eclipse?
Lennart van Ham wrote:In fact, my only question was how to obtain a red (or other color) X.
Lennart van Ham wrote:
Winston Gutkowski wrote:Well, Java has a Color class (java.awt.Color (←click)), and that class has a constant called Color.RED.
So I will try it with this. Can you tell me how to use that constant with my X? My thoughts right now are like this, where colorChip is a string with the name of some color:
In what way is it specifically for eclipse. Eclipse is just an IDE.Lennart van Ham wrote:
But no, it actually is specifically for eclipse.
Tony Docherty wrote:
Lennart van Ham wrote:
Winston Gutkowski wrote:Well, Java has a Color class (java.awt.Color (←click)), and that class has a constant called Color.RED.
So I will try it with this. Can you tell me how to use that constant with my X? My thoughts right now are like this, where colorChip is a string with the name of some color:
You can't do that. A String knows about characters not colours. If you want to output a String in a particular colour you have to tell the output mechanism what colour you want to use. For example If it's a Swing component you will have to call setForeground() passing in the colour you want to use. If you are drawing directly onto the screen the Graphics object has a setColor() method which again you pass in the colour you want to use.
Tony Docherty wrote:
In what way is it specifically for eclipse. Eclipse is just an IDE.
Lennart van Ham wrote:
I think I'm starting to get it, but could you be a little more specific? How do I tell the output mechanism what color I want to use and how do I implement it on my String?
I tried too with setForeground(), but to me it seemed that would only work if I was working a JFrame of some kind.
Lennart van Ham wrote:
Tony Docherty wrote:
In what way is it specifically for eclipse. Eclipse is just an IDE.
Well I meant it only needs to work in Eclipse because it is the only IDE I need to use for this program.
Tony Docherty wrote:I'm not sure how I can be more specific unless you tell us what exactly you want to do ie how you are trying to display the string.
I did say that would only work if you were using a Swing component to display the string, how are you trying to display the String?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |