Hello,
 
I finally found out why my svg images didn't size to the applet window; during the testing I removed the width, height and viewbox by mistake. When you set the viewbox to width and hight of the svg or when you set the width and hight to 100%, the svg is automatically scalled to the canvas size.
 
Jan
----- Original Message -----
From: Jan
Sent: Wednesday, December 28, 2005 6:28 PM
Subject: Automatically size svg drawing to applet window?

Hi,

 

I think the mail didn't work, so excuse me if you got this message twice.

 

A colleague of my made an applet to draw SVG images in an applet window. I changed it a little to let it work in the Jetty web server. Now it works fine. The applet opens full screen, but the SVG is drawn in the upper left corner. I can zoom and pan, but I would like the applet to open full screen with the SVG maximized. To be honest I new very little about Java. I can understand the code and compile Java, but know too little to write Java that opens the SVG full screen.

 

Can somebody help me?

 

The applet and the HTML code to call the applet are given below.

 

Regards,

 

Jan
 
 
 
The applet I use to draw the SVG is as follows:
 
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import javax.swing.JApplet;
import org.apache.batik.swing.*;
import org.apache.batik.swing.gvt.*;
 
import org.w3c.dom.DOMException;
import org.w3c.dom.svg.SVGRect;
 
public class ShowImage extends JApplet {
 
 JSVGCanvas svgCanvas;
 
   public void init() {
      svgCanvas = new JSVGCanvas();
      this.add(svgCanvas, BorderLayout.CENTER);
        String img;         //the images to be displayed
        URL url = "">
 
        //Get the applet parameters.
        String at = getParameter("imageName");
        img = (at != null) ? at : "image";
        System.err.println("parameter imageName: " + img);
 
        try {
            url = "" URL(img);
        } catch (MalformedURLException e) {
            System.err.println("Malformed URL: " + img);
        }
        System.err.println("URL: " + url.toString());
 
        svgCanvas.setURI(url.toString());
 
        getContentPane().add(svgCanvas);
 }
}
The applet is called as follows:
 
<HTML>
<HEAD>
<TITLE>',imgtitle,'</TITLE>
<STYLE type="text/css">
body {background-color: white; color: black; text-align: center;
</STYLE>
</HEAD>
<BODY>
<APPLET code="ShowImage" codebase="" archive="batik-all.jar,xerces_2_5_0.jar,xml-apis.jar" width="95%" height="95%" >
<PARAM name="imageName" value="http://localhost:8585/data/images/svg/fig918220244700500.svg"/>
</APPLET>
<br />Use: <b>SHIFT left mouse button</b> to zoom and <b>SHIFT right mouse button</b> to pan
</BODY>
</HTML>

Reply via email to