Highlight row in the Gantt sheet of a Gantt chart when selecting an activity

Article ID: 2406
Last updated: 29 May, 2018
Article ID: 2406
Last updated: 29 May, 2018
Revision: 3
Views: 626
Posted: 19 Jun, 2011
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

How do you highlight a row in the Gantt sheet of a Gantt chart when selecting an activity in JViews Gantt?

Answer

You can create your own custom IlvHorizontalGanttGrid and override its draw method to set the background of the row to a particular color. To ensure that the row changes color when it is selected, you can add a selection listener to the Gantt chart then redraw the Gantt sheet when an activity is selected.

  • Custom IlvHorizontalGanttGrid:

chart.getGanttSheet().setHorizontalGrid(new IlvHorizontalGanttGrid()

{

public void draw(Graphics dst, IlvGanttGridContext context)

{

super.draw(dst, context);

IlvHierarchyNode[] rows = chart.getSelectedRows();

for (int i = 0; i < rows.length; i++)

{

Graphics2D g2d = (Graphics2D)dst;

IlvTransformer t = context.getTransformer();

IlvTimeConverter converter = context.getTimeConverter();

int xStart = IlvTimeScrollUtil.getPosition(IlvTimeScrollUtil.getMinUnboundedTime(), converter, t);

int xEnd = IlvTimeScrollUtil.getPosition(IlvTimeScrollUtil.getMaxUnboundedTime(), converter, t);

IlvHierarchyNode node = rows[i];

if (chart.isRowVisible(node))

{

IlvGanttRow row = chart.getGanttSheet().getGanttRowByIdentifier(node);

IlvPoint rowTop = new IlvPoint(0, row.getTop());

if (t != null)

t.apply(rowTop);

Rectangle2D shape = new Rectangle2D.Float(xStart, rowTop.y, xEnd - xStart, row.getHeight() - 1);

g2d.setPaint(Color.yellow);

g2d.fill(shape);

}

}

}

});

  • Selection listener:

chart.addSelectionListener(new SelectionListener()

{

public void selectionChanged(SelectionEvent event)

{

chart.getGanttSheet().invalidateView();

chart.getGanttSheet().reDrawViews();

}

});

Attached is a modified version of the Gantt Chart sample that demonstrates this technique. You can replace the sample's file with this new one. The sample is located in the JViews Gantt installation directory under "samplesganttChart".

Note: In order to run this sample with JViews 8.6 and earlier versions, you must comment out the call to ilog.views.util.IlvProductUtil.DeploymentLicenseRequired (comment out lines 134 - 140 of AbstractGanttExample.java).

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2406
Last updated: 29 May, 2018
Revision: 3
Views: 626
Posted: 19 Jun, 2011 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Attached files

Also listed in


Others in this category