2

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.

SaschaSchaefer
  • 149
  • 1
  • 9
  • 2
    For better help sooner, post an [SSCCE](http://sscce.org) – Guillaume Polet Feb 05 '13 at 13:53
  • The project is quite complex, I would not know how to produce a minimal example which reproduces the error. I did however edit my question to show you what I do when the error occurs. Thank you for your help in advance – SaschaSchaefer Feb 05 '13 at 14:22
  • 1
    Then it's like looking for a needle in a haystack. It is very unlikely that someone will be ale to truly help you. – Guillaume Polet Feb 05 '13 at 14:35
  • I figured it out myself. I was calling setOpaque(true) and setBackground(new Color(0f,0f,0f,0f)); for the svgComponent. When I use setOpaque(false) and setBackground(null) to make it tranparent it works without those strange artifacts. – SaschaSchaefer Feb 05 '13 at 15:18
  • 1
    OK, good for you. You may also see these kind of issues if you don't honor the opaque property. – Guillaume Polet Feb 05 '13 at 15:23
  • +1 for illustrations; you can [answer your own question](http://meta.stackexchange.com/q/17463/163188); a similar problem is seen [here](http://stackoverflow.com/q/7213178/230513). – trashgod Feb 05 '13 at 18:01

1 Answers1

0

The problem was, that I had used setOpaque(true) on my Components. Setting it to false has solved it.

SaschaSchaefer
  • 149
  • 1
  • 9