I am writing a drawing application, which uses the JSVGCanvas class of the batik framework. The contentpane of my application is a JLayeredPane, which holds several JPanels stacked on top of each other. One of these Panels holds the JSVGCanvas on which you can draw.
However, when I draw content on the screen, there sometimes remain strange fragments of the screen as you can see in the following picture (The black line was drawn with the mouse):
Screenshot of the drawing http://cip.uni-trier.de/~schaefer/batikbug.jpg
I am not sure whether this is a problem of batik or swing, as a similar bug occurs when I hover over the red JButton which has a custom ImageIcon. In the picture below you can see that the other buttons seem to appear in the background of the red button.
Screenshot of the button http://cip.uni-trier.de/~schaefer/swingbug.png
Does anybody know why this happens or how I can fix that?
Edit:
In the mouseDragged-function I am doing the following:
//newNode was calculated before
Node updateNode = findNodeById(id); //find some node
if(updateNode == null)
{
svgComponent.getSvgCanvas().getSVGDocument().adoptNode(newNode);
svgComponent.getSvgCanvas().getSVGDocument().getDocumentElement().appendChild(newNode);
}
else
{
svgComponent.getSvgCanvas().getSVGDocument().adoptNode(newNode);
svgComponent.getSvgCanvas().getSVGDocument().getDocumentElement().replaceChild(newNode, updateNode);
};
window.contentpane.repaint(); //window is the main JFrame, the contentpane is a JLayeredPane
The svgComponent is a JComponent that contains the JSVGCanvas.