Hi Cyrus,

Yes it is a rather convoluted. The background property only sets the background of the (some) text elements (it draws text on top of bonds with a bounding box). As well as setting the parameter (see below) you also need to fill the background first. Here’s an example:

        IAtomContainer container =...;
        AtomContainerRenderer renderer = new AtomContainerRenderer(Arrays.asList(new BasicSceneGenerator(),
                                                                                 new BasicBondGenerator(),
                                                                                 new BasicAtomGenerator()),
                                                                   new AWTFontManager());

        int w = 512, h = 512;
        Color bg = Color.LIGHT_GRAY;


        BufferedImage img    = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
        Graphics2D    g2     = img.createGraphics();
        Rectangle2D   bounds = new Rectangle2D.Double(0, 0, w, h);
        g2.clearRect(0, 0, w, h);
        renderer.paint(container, new AWTDrawVisitor(g2), bounds, true);
        ImageIO.write(img, "png", File.createTempFile("cdk-img", ".png"));


On 29 Dec 2013, at 21:08, Cyrus Harmon <ch-cdk@bobobeach.com> wrote:

I’m trying and failing to figure out how to change the background color of an image of a molecule I’m rendering with an AtomContainerRenderer. I have to confess to being a bit perplexed by the java idioms for various configurable properties and what not. It seems there’s an unholy mix of interfaces, classes, subclasses, properties, parameters, etc… all trying to do similar things, but this one in particular seems rather confusing.

In the BasicSceneGenerator we have:

   public static class BackgroundColor extends
   AbstractGeneratorParameter<Color> {
    /** Returns the default value.
    * @return {@link Color}.WHITE */
    public Color getDefault() {
           return Color.WHITE;

So we have a concept of a BackgroundColor stored as an inner class, extending AbstractGeneratorParamater. How does one go about changing  the default color? Or is there some sort of “active” background color that is distinct from the “default” background color? Changing current values or defaults by subclassing seems like killing an ant with a machine gun, but, what do I know?

I see that there is also:

   private IGeneratorParameter<Color> backgroundColor = new BackgroundColor();

but given that this is private, that seems rather hard to muck with and I don’t see any getter/setters for backgroundColor.

There is the getParameters method:

   /** {@inheritDoc} */
   public List<IGeneratorParameter<?>> getParameters() {
       return Arrays.asList(
               new IGeneratorParameter<?>[] {

and I suppose I could try overloading that, but, again, that seems a rather heavy-handed approach to trying to change the background color.

Any suggestions? Is there some remedial reading on parameters, abstract parameters, their generators, etc… that I should be reading before asking more stupid questions?



Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
Cdk-devel mailing list