fillRect does not select my color

Hello,

Why does this code draw a black rectangle ?

	@Override
public void paint(GraphicsContext g) {
	super.paint(g);

	int w = g.getClipWidth() / 2;
	int h = g.getClipHeight() / 2;

	Image i = Image.createImage(w, h);

	i.getGraphicsContext().setColor(Colors.BLUE);
	i.getGraphicsContext().fillRect(0, 0, w, h);

	g.drawImage(i, w, h, GraphicsContext.HCENTER_VCENTER);
}

Thank you.

Hello Alban,

The getGraphicsContext() method returns a new object each time it is called. So you should save the object in a local variable if you want to perform multiple operations with it:

GraphicsContext g = i.getGraphicsContext();
g.setColor(Colors.BLUE);
g.fillRect(0, 0, w, h);

Best regards,
Andy