Customizing the vertical lines of the gantt sheet

Article ID: 2384
Last updated: 29 May, 2018
Article ID: 2384
Last updated: 29 May, 2018
Revision: 3
Views: 906
Posted: 14 Dec, 2010
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How to customize IlvVerticalGanttGrid?

Answer

You can customize the vertical lines that show on the Gantt sheet by extending the IlvVerticalGanttGrid class and overriding the method draw(Graphics dst, IlvGanttGridContext gc).

You can for example override the draw method as follows to specify a particular paint and stroke for the vertical lines :

public class MyVerticalGanttGrid extends IlvVerticalGanttGrid {
  public void draw(Graphics dst,IlvGanttGridContext context) {
    Graphics2D g2d = (Graphics2D) dst;
    g2d.setPaint(getForeground());
    g2d.setStroke(new BasicStroke(6));
    Shape[] shapes = getGridShapes(dst, false, context);
    for (int i = 0; i < shapes.length; i++) {
      g2d.draw(shapes[i]);
    }
  }
};

Then you simply set your customized vertical Gantt grid to your Gantt sheet as follows :

MyVerticalGanttGrid grid = new MyVerticalGanttGrid();
sheet.setVerticalGrid(grid);

You can also, for instance, choose to draw one vertical line per hour as in the screen shot below. In order to achieve this, you need to create a class which extends IlvVerticalGanttGrid and override the draw method. In this method, you need to test if the lvHourTimeScaleRow is visible, and if it is visible, compute the array of all rectangles that correspond to every hour in the visible part of the Gantt chart, and draw a flat rectangle corresponding to every visible hour. For other type of rows (for instance for IlvMonthTimeScaleRow), just call super.draw(...).

Here is the source code of the above screen shot, based on the ganttChart sample.

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2384
Last updated: 29 May, 2018
Revision: 3
Views: 906
Posted: 14 Dec, 2010 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category