xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Todd Wilson <todd_wil...@byu.edu>
Subject Re: Using transparency over an underlying component
Date Tue, 12 Mar 2002 22:26:25 GMT
Thanks for the reply, Thomas.  Unfortunately that just changed the 
background from white to black, instead of allowing the blue background 
of the underlying JFrame to show through.  Here's my revised code, just 
let me know if I'm misunderstanding anything:


=============================================================
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

import org.apache.batik.swing.*;
import org.apache.batik.swing.gvt.*;

public class TransTest extends JFrame
{
   public TransTest()
   {
     // Kill the app when the window closes.
     this.addWindowListener( new WindowAdapter() { public void 
windowClosing( WindowEvent e ) { System.exit( 0 ); } } );

     // Create an SVG canvas.
     JSVGCanvas svgCanvas = new JSVGCanvas();

     // Make sure that the canvas isn't opaque.
     svgCanvas.setBackground( new Color( 0, 0, 0 ) );
     svgCanvas.setOpaque( false );
     System.out.println( "isOpaque: " + svgCanvas.isOpaque() );

     // Tell the canvas where to find the SVG.
     svgCanvas.setURI( "file:/path/to/svg/test.svg" );

     // Turn the background of the frame a bright blue so that if the
     // SVG is transparent the blue will shine through.
     this.getContentPane().setBackground( Color.blue );

     // Add the SVG to the frame.
     this.getContentPane().add( svgCanvas );

     // Make the frame visible and pack it so that it can be
     // displayed.
     this.setVisible( true );
     this.pack();
   }


   public static void main( String[] args )
   {
     TransTest transTest = new TransTest();
   }
}
=============================================================


Todd



Thomas E Deweese wrote:

>>>>>>"TW" == Todd Wilson <todd_wilson@byu.edu> writes:
>>>>>>
> 
> TW> Transparency within an SVG seems to work just fine, meaning shapes
> TW> overlaying each other where "fill:none" can be designated in order
> TW> to allow some shapes visible through other shapes.  However, we're
> TW> hoping to accomplish basically what a transparent GIF
> TW> allows--portions of an image are transparent and allow whatever
> TW> the SVG is rendred on top of to show through the image.  So, for
> TW> example, I could render an SVG on top of a JFrame or JPanel that
> TW> has a blue background, and portions of that blue background would
> TW> be visible through the SVG because portions of the SVG are
> TW> transparent.
> 
>     You need to set the background of the JSVGCanvas to something
> other than white.  I suggest transparent black:
> 
>      // Make sure that the canvas isn't opaque.
> +    svgCanvas.setBackground(new Color(0,0,0,0));
>      svgCanvas.setOpaque( false );
>      System.out.println( "isOpaque: " + svgCanvas.isOpaque() );
>       
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


Mime
View raw message