简体   繁体   English

秋千/蜡染的奇怪行为

[英]Strange behaviour of swing/batik

I am writing a drawing application, which uses the JSVGCanvas class of the batik framework. 我正在编写一个绘图应用程序,该应用程序使用蜡染框架的JSVGCanvas类。 The contentpane of my application is a JLayeredPane, which holds several JPanels stacked on top of each other. 我的应用程序的内容窗格是一个JLayeredPane,它包含几个JPanel相互堆叠。 One of these Panels holds the JSVGCanvas on which you can draw. 这些面板之一包含您可以在其上绘制的JSVGCanvas。

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 绘图的屏幕截图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. 我不确定这是蜡染还是摇摆问题,因为当我将鼠标悬停在具有自定义ImageIcon的红色JButton上时,会发生类似的错误。 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 按钮的屏幕截图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: 在mouseDragged函数中,我正在执行以下操作:

//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. svgComponent是一个包含JSVGCanvas的JComponent。

The problem was, that I had used setOpaque(true) on my Components. 问题是,我在组件上使用了setOpaque(true)。 Setting it to false has solved it. 将其设置为false已经解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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