Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:32:31+00:00 2026-05-31T06:32:31+00:00

I’ve followed guidelines here: http://xmlgraphics.apache.org/batik/faq.html and read through pages of their mailing list. I’ve

  • 0

I’ve followed guidelines here: http://xmlgraphics.apache.org/batik/faq.html and read through pages of their mailing list. I’ve tried everything I can think of. Here is a very simple example of what I am trying to accomplish. Layout manager is: http://java.sun.com/products/jfc/tsc/articles/tablelayout/ Or you can use gridbag or whatever you like. XmlHelper is in-house lib, you can substitue with your own. Not included to cut down on code size.

Basically after you hit the “up” button (short for update), it modifies the DOM and adds a new element, yet i dont see the SVG update.

..

public class SvgRefresh extends JFrame
{
  private static final NAMESPACE = "http://www.w3.org/2000/svg";

  private JSVGCanvas canvas;
  private Document document;
  private JButton button;

  public static void main(String[] args)
  {
    SvgRefresh svgRefresh = new SvgRefresh();

    svgRefresh.pack();
    svgRefresh.setVisible(true);
  }

  public SvgRefresh()
  {
    canvas = new JSVGCanvas();
    initialize();
  }

  private void initialize()
  {
    double[][] size = {{ TableLayout.FILL, 0.1, TableLayout.FILL}, { TableLayout.FILL, 0.1 }};
    getContentPane().setLayout(new TableLayout(size));

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    document = XmlHelper.readDocumentFromFile("F:/SVG/svg01.svg");

    canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
    canvas.setDocument(document);

    document = canvas.getSVGDocument();

    getContentPane().add(canvas, "0, 0, 2, 0");
    getContentPane().add(getButton(), "1, 1");
  }

  private JButton getButton()
  {
    if(button == null)
    {
      button = new JButton("Up");

      button.addActionListener(new ActionListener()
      {
        @Override
        public void actionPerformed(ActionEvent e)
        {
          UpdateManager updateManager = canvas.getUpdateManager();

          updateManager.getUpdateRunnableQueue().invokeLater(new Runnable()
          {
            @Override
            public void run()
            {
              Element root = document.getDocumentElement();
              Element text = document.createElementNS(NAMESPACE, "text");

              text.setAttributeNS(NAMESPACE, "x", "100");
              text.setAttributeNS(NAMESPACE, "y", "100");
              text.setTextContent("It worked!!!");

              root.appendChild(text);
              System.out.println("ran");
            }
          });
        }
      });
    }

    return button;
  }
}

Original SVG (made in AI, and i edited all content out except for the text element):

<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="application/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" enable-background="new 0 0 400 200" version="1.1" xml:space="preserve" width="400px" preserveAspectRatio="xMidYMid meet" viewBox="0 0 400 200" height="200px" x="0px" y="0px">
  <text x="40" y="40">Default text</text>
</svg>

Code above doesn’t include writing to file – I’ve excluded for space. SVG after pressing UP button and written to file (to check namespace). When written to file after pressing “UP” button this is produced – which looks perfect to me.

<?xml version="1.0" encoding="UTF-8"?><svg xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" contentScriptType="application/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" enable-background="new 0 0 400 200" version="1.1" xml:space="preserve" width="400px" preserveAspectRatio="xMidYMid meet" viewBox="0 0 400 200" height="200px" x="0px" y="0px">
  <text x="40" y="40">Default text</text>
  <text x="100" y="100">It worked!!!</text>
</svg>

Thanks for the help. Oh and to encourage research, and people taking time with their answers, I will probably wait around 24 hours before awarding an answer. So take your time and run the code if you want.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:32:33+00:00Added an answer on May 31, 2026 at 6:32 am

    Just change

              text.setAttributeNS(NAMESPACE, "x", "100");
              text.setAttributeNS(NAMESPACE, "y", "100");
    

    to

              text.setAttributeNS(null, "x", "100");
              text.setAttributeNS(null, "y", "100");
    

    and it will update fine

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I have thousands of HTML files to process using Groovy/Java and I need to
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to loop through a bunch of documents I have to put
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.