If you want to visualize a line of a shape with two side-by-side lines, each in a different color, you can paint the line twice:

  • Once in the first color on one side of the shape

  • Another time using the second color on the other side of the shape.

You paint the line twice by configuring two painters on the layer.

This code snippet illustrates the use of two painters:

//To have two lines side by side, we will paint twice.
//Each time, we use a line style that is only on one side of the shape
//First we create the line styles
Polygon polygon = new Polygon(new int[]{0, 5, 5, 0}, new int[]{0, 0, 3, 3}, 4);
TLcdGXYComplexStroke left = new TLcdGXYComplexStroke(new Shape[]{polygon}, new double[]{3d}, true);
polygon = new Polygon(new int[]{0, 5, 5, 0}, new int[]{0, 0, -3, -3}, 4);
TLcdGXYComplexStroke right = new TLcdGXYComplexStroke(new Shape[]{polygon}, new double[]{3d}, true);

//Then we create the painters configured with those styles
TLcdGXYShapePainter painterLeft = new TLcdGXYShapePainter();
painterLeft.setLineStyle((graphics, object, m, context) -> {
  graphics.setColor(Color.RED);
  ((Graphics2D) graphics).setStroke(left);
});

TLcdGXYShapePainter painterRight = new TLcdGXYShapePainter();
painterRight.setLineStyle((graphics, object, m, context) -> {
  graphics.setColor(Color.BLUE);
  ((Graphics2D) graphics).setStroke(right);
});

//Finally, create the layer and configure both painters on it
TLcdGXYLayer layer = TLcdGXYLayer.create(model);
layer.setGXYPainterProviderArray(new ILcdGXYPainterProvider[]{painterLeft, painterRight});

which results in:

gxy side by side painting

Other examples of cases for using an array of painter providers are: