Introduction
The system layer RowLayer supports pluggable renderers in order to customize the background of each row depending on the row type. In the tutorial we have seen that we can have Aircraft rows and Crew rows. For clarity these two rows could have different background colors. This is something that could be done with a row renderer.
Row Renderer
All row renderers have to subclass RowRenderer. This class defines a final public method called draw() that gets called by the framework. It then calls the protected method drawRow() which subclasses can override. A possible implementation might look like this:
public class AircraftRowRenderer extends RowRenderer<Aircraft> { public AircraftRowRenderer(GraphicsBase<?> graphics) { super(graphics, "Aircraft Row Renderer"); } protected void drawRow(Aircraft row, GraphicsContext gc, double w, double h, boolean selected, boolean hover, boolean highlighted, boolean pressed) { gc.setFill(Color.ORANGE); gc.fillRect(0, 0, w, h); } }
This renderer can now be registered with the RowLayer like this:
GraphicsBase<?> graphics = ganttChart.getGraphics(); graphics.getSystemLayer(RowLayer.class).setRowRenderer( Aircraft.class, new AircraftRowRenderer());
The RowRenderer base implementation is attached to this page and can be downloaded here: