简体   繁体   中英

Strange behaviour of swing/batik

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM