You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jane Singer <js...@cc.huji.ac.il> on 2002/11/28 20:36:43 UTC
Using JSVGCanvas within a JScrollPane
First I want to thank you all for the incredibly specific and correct answers that I've gotten for all my inquiries on this list (without exception)!
I'm trying to put a JSVGCanvas inside a scroll box. I need to do this because I'm creating a graphic representation of a musical abstraction - I have notes with graphical signs underneath, the SVG can contain anywhere from 1 - 40 melodies each with it's own graphical rendition. I want to be able to scroll down and look at them all.
The SVG file is fine (almost), the problem is placing it inside the JScrollPane. What happens is that it always resizes itself to fit the pane, so that the scroll bars never show up. If I make the JFrame a full screen they show up full size, if I make it half screen size, the whole SVG shows up reduced.
I think this may have to do with the SVG attributes. There are so many factors that affect this - size, transformation, viewbox, etc. I've tried all different kinds of combinations. I admit I do no totally understand these all.
Here are the svg attibutes:
<svg width="1000" height="600" viewBox="-10 0 150 100" preserveAspectRatio="xMinYMin meet" xml:space="collapse">
Here is the code "this" is a JFrame:
//this is the whole svg dimension, expanded (y only) according to the number of melodies
Dimension d = new Dimension((scrnSize.width ) - 2, ((melcount + 2) * (scrnSize.height - 80) / 2));
svgCanvas.setEnabled(true);
svgCanvas.setSize(d);
svgCanvas.setVisible(true);
SVGUtilities.writeSVG2file(SVGdoc, "c:\\temp\\out.svg");
svgCanvas.setSVGDocument(SVGdoc);
//this is the smaller dimension, the lower half of the screen
Dimension sd = new Dimension((scrnSize.width ) - 2, (scrnSize.height - 80) / 2);
this.setSize(sd);
this.setLocation(0, scrnSize.height/ 2);
JScrollPane svgscrollpane = new JScrollPane(svgCanvas);
//the scrolll pane size, the lower part of the screen
svgscrollpane.setSize(sd);
svgscrollpane.setVisible(true);
svgscrollpane.setEnabled(true);
svgscrollpane.setAutoscrolls(true);
//add the scrollpane to the JFrame
this.getContentPane().add(svgscrollpane);
this.setVisible(true);
this.setEnabled(true);
Thanks for any suggestions!
Jane