Houp
Houp

Reputation: 145

How to change text in Text element

I have this line in my SVG file:

<text id="region1Text" class="regionText" x="77" y="167">2</text>

I can get an object of Text class with this but I cant see any usable method for changing "2" to another number. The appendText method seems to do nothing and I see there is no "setText" method.

My code:

StringReader reader = new StringReader(svgInString);
uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); 
Text text = (Text) diagram.getElement("region1Text");
text.appendText("20");

When debugging I can see the content variable of the text object is set to "2"(so I think that text element is made correctly) but I'm not able to change it.

Upvotes: 1

Views: 752

Answers (1)

horec
horec

Reputation: 404

After appending the text, you have to use text.rebuild() function. In total it looks like this:

StringReader reader = new StringReader(svgInString);
uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage");
SVGDiagram diagram = SVGCache.getSVGUniverse().getDiagram(uri); 
Text text = (Text) diagram.getElement("region1Text");
text.appendText("20");
text.rebuild();

Upvotes: 0

Related Questions