Creating a Timeline

In order to complete our static interactive Gantt Chart we will need to be able to see the actual calendar the days in which the schedule is for.
  1. The part of the chart which will show this is the column header which appears above the drawn diagram.
  2. Be able to set a time range so that the user will be limited to the area of the chart which contains entries instead of having access to scroll from 1970 to 2010.

Creating the Header

The Header is actually rendered using the same mechanism as the rest of the chart to create the header we need to do the following steps:
  1. Determine the Column from the table being used
  2. Specify the header in the column
The column which we are looking for is the first column of the second table put simply this is
table.getColumn(1).getColumn(0).
The second part is to specify the header value to be renderered as with the standard JTable this is done via column.setHeaderValue(Object). The value that we will specify however is a drawing the state the GanttEntryHelper has a helper method for creating this GanttEntryHelper.createCalendar());

The code has been inlcuded below for your convenience:
// ** NEW CODE **
// This code is used to set the GanttHeader in the far right table
// this is all that is required the table will deal with the rest.
{
// we take the second tables column model as this is where we want to render
// the calendar header on top
TableColumnModel columnModel = table.getColumnModel(1);
 
// from this we then take the column note: there should only be one column in this table
TableColumn column = columnModel.getColumn(0);
 
// We now set the header for this column to be the calendar drawing state
column.setHeaderValue(GanttEntryHelper.createCalendar());
}

Specifiying the Time Range

The next stage is to specify the time range there is two parameters a start time and a finish time.
  • The Start is the furthest the application can scroll to the left
  • The Finish point is the furthest the application can scroll to the right.
If this method has been called before the chart has been rendered for the first time the chart will appear in this position otherwise the bounds will remain the same until the user interacts with the chart.

//**NEW CODE**
//This code is used to set the start and end points of the time line
{
table.setTimeRange(new Date(2005 - 1900, 1, 1), new Date());
}