(Solved) Graphics2D.setColor(c) Calls Ignored

Calling to setColor and setStroke in certain sections of my code does not affect the state of the graphics object. I do not create any new graphics objects at any point. The following four lines creates the output below.

      System.out.print(g.getColor());
      g.setColor(debugFillColor);
      System.out.println(debugFillColor);
      System.out.print(g.getColor());

Output:

java.awt.Color[r=255,g=0,b=0]
java.awt.Color[r=0,g=0,b=0]
java.awt.Color[r=255,g=0,b=0]

I set the color to red before calling drawString. debugFillColor is black.

I am not aware of any function that would cause that.

Not much we can do just with this basic code segment, maybe post the entire paint() method?

  @Override public void paint(Graphics g)
  {
    Graphics2D g2 = (Graphics2D) g;
    g2.setStroke(new BasicStroke());
    final String mouseStr = "Mouse: " + (lmb ? 'L' : '-') + (mmb ? 'M' : '-') + (rmb ? 'R' : '-') + " ";
    g2.clearRect(0, 0, pixelWidth, pixelHeight);
    g2.setColor(Color.red);
    g2.setComposite(AlphaComposite.SrcOver);
    g2.drawString(mouseStr, 2, pixelHeight - 2);
    drawThings(g2);
  }
  
  private void drawThings(Graphics2D g)
  {
    for(Thing t : things)
    {
      t.drawDebug(g);
    }
  }
  public void drawDebug(Graphics2D g)
  {
    if(debugFillColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.fill(r);
    }
    if(debugLineColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.setStroke(thickStroke);
      g.draw(r);
    }
  }
  
  protected final Composite solidComposite = AlphaComposite.SrcOver;
  protected final Stroke thickStroke = new BasicStroke(2f);

I found one problem.

  public void drawDebug(Graphics2D g)
  {
    if(debugFillColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor);
      g.setComposite(solidComposite);
      g.fill(r);
    }
    if(debugLineColor != null)
    {
      Rectangle2D.Double r;
      r = new Rectangle2D.Double(left, top, right - left, bottom - top);
      g.setColor(debugFillColor); // This line <------------------------------
      g.setComposite(solidComposite);
      g.setStroke(thickStroke);
      g.draw(r);
    }
  }
  
  protected final Composite solidComposite = AlphaComposite.SrcOver;
  protected final Stroke thickStroke = new BasicStroke(2f);

[/quote]
setColor of Graphics calls setPaint of Graphics2D. setColor does not specify what happens if null is passed. setPaint does nothing with a null reference. How annoying.

Now I will have to see what the problem with setStroke was.