Hi Mark.

Mark Fortner:
> I'm trying to create an SVG-based widget system using batik.  I've created a
> proof-of-concept app, but I'm having problems getting the widget to display
> without a background color.  I've used the information in the following bug
> report to set the alpha to 0 (
> http://issues.apache.org/bugzilla/show_bug.cgi?id=40392) but that doesn't
> seem to fix the problem.

It works for me.  Here is an example that displays a semi-transparent
JSVGCanvas above another component:

  // -- TransparentCanvas.java --

  import java.awt.Color;
  import java.awt.Container;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.OverlayLayout;
  import javax.swing.SwingConstants;
  import org.apache.batik.dom.svg.SVGDOMImplementation;
  import org.apache.batik.swing.JSVGCanvas;
  import org.w3c.dom.DOMImplementation;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.svg.SVGDocument;
  
  public class TransparentCanvas {
  
      public static void main(String[] args) {
          JFrame frame = new JFrame("Transparent JSVGCanvas test");
          frame.setSize(400, 300);
          Container contentPane = frame.getContentPane();
          contentPane.setLayout(new OverlayLayout(contentPane));
  
          JLabel label = new JLabel("A JLabel behind the JSVGCanvas",
                                    SwingConstants.CENTER);
          contentPane.add(label);
  
          JSVGCanvas canvas = new JSVGCanvas();
          canvas.setBackground(new Color(0, true));
          canvas.setSVGDocument(buildDocument());
  
          contentPane.add(canvas);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
      }
  
      private static SVGDocument buildDocument() {
          DOMImplementation di =
              SVGDOMImplementation.getDOMImplementation();
          String SVGNS = "http://www.w3.org/2000/svg";;
          Document doc = di.createDocument(SVGNS, "svg", null);
          Element svg = doc.getDocumentElement();
          svg.setAttributeNS(null, "viewBox", "0 0 100 100");
          Element circle = doc.createElementNS(SVGNS, "circle");
          circle.setAttributeNS(null, "cx", "50");
          circle.setAttributeNS(null, "cy", "50");
          circle.setAttributeNS(null, "r", "50");
          circle.setAttributeNS(null, "fill", "yellow");
          circle.setAttributeNS(null, "fill-opacity", "0.5");
          svg.appendChild(circle);
          return (SVGDocument) doc;
      }
  }

-- 
Cameron McCormack, http://mcc.id.au/
        xmpp:[EMAIL PROTECTED]  ▪  ICQ 26955922  ▪  MSN [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to