xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Armstrong" <andrew_armstr...@bigpond.com>
Subject How to redisplay a SVG text item on a JSVGCanvas?
Date Sat, 13 Apr 2002 12:52:06 GMT
I have been trying to programmatically update the value of an SVG text
element and have the new value re-painted on a JSVGCanvas. The problem is
the new value is never seen, no matter what I try. How do I go about getting
this to work?

I'm using JDK1.3.1, Win2000, Batik 1.5 beta - a CVS version as at

This is what I am currently doing:

1. I create an instance of MyJSVGCanvas which sets the document state to
ALWAYS_DYNAMIC in its constructor.

2. I load the SVG file by invoking setURI on MyJSVGCanvas. The SVG file is
displayed ok. In it are several text elements which have known "id"
attributes, such as "R1_value" which will have their values set by the app.
For example:
       <g id="R1" transform="matrix(1 0 0 1 18 58)">
        <use x="0" y="0" xlink:href="#resistor"/>
        <text id="R1_label" font-size="24" font-family="Technical" x="60px"
        <text id="R1_value" font-size="24" font-family="Arial" x="60px"

3. Elsewhere in the app, the user clicks a JTable entry which ultimately
results in a call to MyJSVGCanvas.setTextValue("R1_value", "270"), to
display textual information from that table entry on the JSVGCanvas.

4. In setTextValue() I find the element in the DOM with the specified id,
retrieve the first child node of that element, and then update the child
node with the specified new text value ("270" in this case).

5. I expect the change to the DOM to be seen by Batik and have it do
whatever it needs to do to redisplay the new text value, however the new
value is never redisplayed. The debug output from the run() method looks
TextUpdater.run org.apache.batik.dom.GenericText (at) 74db2c = 270

Below is a (cutdown) version of my JSVGCanvas...

import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.swing.svg.JSVGComponent;
import org.w3c.dom.Node;

public class MyJSVGCanvas extends JSVGCanvas

 public MyJSVGCanvas()

 public void setTextValue(String id, String newValue)
  org.w3c.dom.Element e = getSVGDocument().getElementById(id);
  Node firstChild = e.getFirstChild();
TextUpdater(firstChild, newValue));

 private class TextUpdater implements Runnable
  private Node _node;
  private String _value;

  public TextUpdater(Node node, String value)
   _node = node;
   _value = value;

  public void run()
   System.out.println("TextUpdater.run " + _node + " = " + _value);


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

View raw message