Draw a border around shapes in the canvas with JavaFx

Shantanu Chandra picture Shantanu Chandra · Dec 9, 2014 · Viewed 9.3k times · Source

I have drawn a straight line in a canvas and filled with a solid color. I want to border this straight line with a black colored border.

Answer

Mailkov picture Mailkov · Dec 9, 2014

You can use two fillRect with different size and color

example:

final Canvas canvas = new Canvas(250,250);
GraphicsContext gc = canvas.getGraphicsContext2D();

gc.setFill(Color.BLUE);
gc.fillRect(0,0,100,20);
gc.setFill(Color.RED);
gc.fillRect(1,1,98,18);