Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Using more than one foregroundcolor in figure?(I want to draw several lines with different colors, but it seems they all have same color no matter what I do.)
Using more than one foregroundcolor in figure? [message #640579] Mon, 22 November 2010 14:27 Go to next message
Mikkel Jonassen is currently offline Mikkel JonassenFriend
Messages: 24
Registered: September 2010
Junior Member
Hi Experts Smile

I am trying to draw different lines and each line should have its own color.

I have a little example that shows what I am trying:

import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Rectangle;

public class ColorLines extends RectangleFigure {

	@Override
	protected void fillShape(Graphics graphics) {
		Rectangle bounds = this.getBounds().getCopy();
		this.setBackgroundColor(ColorConstants.green);
		super.fillShape(graphics);
		this.setForegroundColor(ColorConstants.blue);
		graphics.drawLine(bounds.x, bounds.y, bounds.x+bounds.width, bounds.y+bounds.height);
		this.setForegroundColor(ColorConstants.red);
		graphics.drawLine(bounds.x+bounds.width, bounds.y, bounds.x, bounds.y+bounds.height);
	}
}


Anyway what I get out of this is a rectangle with a green background color which is correct, but all the two lines inside have the same color as the last set foregroundcolor. (red).

So is i not possible to use multipleforeground colors while drawing?.
If it is possible how do I fix it?

Thanks alot for your time and help!

Regards Mikkel
Re: Using more than one foregroundcolor in figure? [message #640591 is a reply to message #640579] Mon, 22 November 2010 14:37 Go to previous messageGo to next message
h1055071 is currently offline h1055071Friend
Messages: 335
Registered: July 2009
Senior Member
On 22/11/2010 14:27, Mikkel Jonassen wrote:
> Hi Experts :)
>
> I am trying to draw different lines and each line should have its own
> color.
>
> I have a little example that shows what I am trying:
>
>
> import org.eclipse.draw2d.ColorConstants;
> import org.eclipse.draw2d.Graphics;
> import org.eclipse.draw2d.RectangleFigure;
> import org.eclipse.draw2d.geometry.Rectangle;
>
> public class ColorLines extends RectangleFigure {
>
> @Override
> protected void fillShape(Graphics graphics) {
> Rectangle bounds = this.getBounds().getCopy();
> this.setBackgroundColor(ColorConstants.green);
> super.fillShape(graphics);
> this.setForegroundColor(ColorConstants.blue);
> graphics.drawLine(bounds.x, bounds.y, bounds.x+bounds.width,
> bounds.y+bounds.height);
> this.setForegroundColor(ColorConstants.red);
> graphics.drawLine(bounds.x+bounds.width, bounds.y, bounds.x,
> bounds.y+bounds.height);
> }
> }
>
>
> Anyway what I get out of this is a rectangle with a green background
> color which is correct, but all the two lines inside have the same color
> as the last set foregroundcolor. (red).
>
> So is i not possible to use multipleforeground colors while drawing?.
> If it is possible how do I fix it?
>
> Thanks alot for your time and help!
>
> Regards Mikkel

You should set the color on the graphics object:

graphics.setForegroundColor(Color rgb);

PB
Re: Using more than one foregroundcolor in figure? [message #640694 is a reply to message #640591] Mon, 22 November 2010 20:29 Go to previous message
Mikkel Jonassen is currently offline Mikkel JonassenFriend
Messages: 24
Registered: September 2010
Junior Member
Thank you so much Phillip.

I have totaly missed that and it solved my problem.

Thanks!
Previous Topic:Disappearing Buttons
Next Topic:Some exception when I opened the gef editor
Goto Forum:
  


Current Time: Thu Mar 28 22:18:05 GMT 2024

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

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

Back to the top