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. Take Week time unit for instance, it means each scale in the time axis is represent a 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
config.setAllowAccurateTaskBar(true);//Set true if you want to show accurate task bar.
...
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 Time(2008, 1, 1), new Time(2008, 1, 30));
Task task1 = new Task("Sub-task 1", new Time(2008, 1, 1), new Time(2008, 1, 5));
Task task2 = new Task();
task2.setName("Sub-task 2");
task2.setStart(new Time(2008, 1, 6));
task2.setEnd(new Time(2008, 1, 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. e.g. 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.