Hi, I am trying to load SVG document created in third party
application. Display it in my Java application, and detect mouse
clicks on different svg elements.
I am new to batik so probably I am doing something wrong. Here is my code:

                String svgUri = new File("data/test.svg").toURI().toString();

                JSVGCanvas svg = new JSVGCanvas();
                try
                {
                        String parser = 
XMLResourceDescriptor.getXMLParserClassName();
                        SAXSVGDocumentFactory f = new 
SAXSVGDocumentFactory(parser);
                        SVGDocument doc = (SVGDocument)f.createDocument(svgUri);


                        EventTarget node = (EventTarget) 
doc.getElementById("rect1");  //
just for test, such element exists.
                        if(node != null)
                        {
                                node.addEventListener("click", new 
EventListener()
                                {
                                        @Override
                                        public void handleEvent(Event evt)
                                        {
                                                int x = ((DOMMouseEvent) 
evt).getClientX();
                                                int y = ((DOMMouseEvent) 
evt).getClientY();
                                                
JOptionPane.showMessageDialog(GamingInterfaceClient.this,
"Click: " + x + "," + y);
                                        }
                                }, false);
                        }
                        
                        svg.setSVGDocument(doc);
                }
                catch(IOException ex)
                {
                        // ...
                }

then I just display JSVGCanvas svg inside a panel on JFrame.

The problem is that mouse clicks does not get detected, no matter where I click.

Any code examples how to make that work?

Thanks,
Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to