Question

I'm using the FlexGantt Javax Swing package (http://www.dlsc.com/) to display some Gantt charts. The trouble I'm having is that I can't figure out how to change the color of a DefaultTimelineObject that I've extended into my own class. Actually, about the only colors I seem able to change are the ones that are for the background colors of the Gantt rows.

Was it helpful?

Solution 2

So I did manage to figure this out. It's kind of complicated, or at least it was to me, as I didn't really (and still don't quite) understand the Model-View-Controller pattern used by FlexGantt. So, here's where we go. We need a TimelineObjectRenderer class that extends the DefaultTimelineObjectRenderer. That renderer has a method that returns a Component, called getTimelineObjectRendererComponent. In that method, I needed to call the methods setActivityFillColor1 and setActivityFillColor2, which are the two colors used to create the vertical blend on an item.

The important code is here:

public class myTimelineObjectRenderer extends DefaultTimelineObjectRenderer {
    public Component getTimelineObjectRendererComponent(
        setActivityFillColor1(new Color(r,g,b));
        setActivityFillColor2(new Color(r,g,b));
    }
} //there is other code in this class, not mentioned here

That's the first part.

The next part is where we connect that Renderer with the GanttChart object itself, and tell the Chart where to find the Renderer needed for each item.

The two lines I used for that are as follows:

GanttChart gc = new GanttChart();
gc.getLayerContainer().setTimelineObjectRenderer(
          new myTimelineObject().getClass(),new myTimelineObjectRenderer());

So, I got there eventually, made it work, and am very impressed with the flexibility of the FlexGantt package.

OTHER TIPS

You should post this question in the FlexGantt newsgroup at http://groups.google.com/group/flexgantt

Regards,

Dirk (FlexGantt author)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top