Here are some common approaches for using SwiftGantt, you can
have simple Gantt Chart step by step.
1. Construct the main
class org.swiftgantt.GanttChart of SwiftGantt first, which
is inherited from Swing component javax.swing.JScrollPanel.
GanttChart gantt = new GanttChart();
2. Set
time unit of Gantt Chart. If the time unit is Week, it means each
scale in the time axis is stand for one week:
gantt.setTimeUnit(TimeUnit.Week);
3. you can
decorate you Gantt Chart through the configuration class "Config",
by setting the color, width, height for elements in Gantt Chart.
Since version 0.3.0, you can set the span of working days in each
week and span of working hours in each day. See more detail in the
API documentation.
Config config =
gantt.getConfig();
config.setWorkingTimeBackColor(Color.YELLOW);//Set
background color for working
time.
config.setTimeUnitWidth(50);//Set width for time
unit
config.setWorkingDaysSpanOfWeek(new int[]{Calendar.MONDAY,
Calendar.THURSDAY})//Set span of working days in each week
...
4. Create data model "GanttModel" for Gantt Chart, all tasks
information you want to display in GanttChart componenet are via
this model class.
GanttModel model = new GanttModel();
5. Set
start time and end time for schedule:
model.setKickoffTime(new GregorianCalendar(2008, 0,
1));
model.setDeadline(new GregorianCalendar(2008, 0,
30));
6. Create basic element for Gantt Chart:Task. A
Task object shows as a bar in the Gantt Chart. Each Task object
can contains any sub tasks, to form a tree structure. If a Task
object contains sub tasks, it will be a Task group, which shows as
different shape in Gantt Chart. Following is a Task group
"taskGroup" with 2 sub tasks, "task1" and "task2":
Task taskGroup = new Task("My Work 1", new
GregorianCalendar(2008, 0, 1), new GregorianCalendar(2008, 0,
30));
Task task1 = new Task("Sub-task 1", new
GregorianCalendar(2008, 0, 1), new GregorianCalendar(2008, 0,
5));
Task task2 = new Task();
task2.setName("Sub-task
2");
task2.setStart(new GregorianCalendar(2008, 0,
6));
task2.setEnd(new GregorianCalendar(2008, 0, 18));// Since
version 0.3.0, the end time set to a task is included in duration
of the task
taskGroup.add(new Task[]{task1,
task2});
7. Attach the dependency between tasks. If
task B must start after task A has completed, you should set task
A as predecessor task to task B:
task2.addPredecessor(task1);
8. Put the
main task group for schedule into model object, and set the model
object to GanttChart object:
model.addTask(taskGroup);
gantt.setModel(model);
after that, you can see Gantt Chart displaying in the
SwiftGantt component.