如何在Java中使透明SVG透明?
我的 SVG 文件实际上是空的,还没有元素。我将通过添加元素在java代码中操作它。 SVG 文件将被插入到滚动窗格中。问题是,即使 SVG 文件实际上是空的,滚动窗格也不透明,即使我已经将其设置为透明。
这是 SVG 文件(我从客户端获得):
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<svg version="1.1"
baseProfile="full"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events">
id="chart"
width="1366px" height="768px" viewBox="0 0 1366 768" >
<defs>
<!-- some template here -->
</defs>
</svg>
这是滚动窗格部分(canvasDiagram 是 SVGCanvas)。
// the instantiation part
canvasDiagram.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
canvasDiagram.setURI(getClass().getResource("path to svg file").toString());
scrollPane = new JScrollPane(canvasDiagram){
{
setOpaque(false);
getViewport().setOpaque(false);
}
};
滚动窗格不是透明的而是白色的。我尝试使用透明的 jPanel 及其工作插入滚动窗格内容,因此我相信由于 canvasDiagram 而出现的白色内容。你能帮我让canvasDiagram的空白部分变得透明吗?
I have SVG file that actually empty, that have no element, yet. I will manipulate it in the java code by adding element. The SVG file will be inserted in a scrollpane. The problem is even the SVG file actually empty, the Scrollpane not transparent even if I have already set it transparent.
Here is the SVG file (I got it from client):
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 13.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 14948) -->
<svg version="1.1"
baseProfile="full"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ev="http://www.w3.org/2001/xml-events">
id="chart"
width="1366px" height="768px" viewBox="0 0 1366 768" >
<defs>
<!-- some template here -->
</defs>
</svg>
and here is the scroll pane part (canvasDiagram is the SVGCanvas).
// the instantiation part
canvasDiagram.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
canvasDiagram.setURI(getClass().getResource("path to svg file").toString());
scrollPane = new JScrollPane(canvasDiagram){
{
setOpaque(false);
getViewport().setOpaque(false);
}
};
The scrollpane is not transparent but white. I tried to insert the scroll pane content with transparent jPanel and its work so I believe the white content because of the canvasDiagram. Can you help me to make the empty part of canvasDiagram really transparent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现设置带有 alpha 值的背景比设置 isOpaque(false) 更可靠
I found that setting a background with alpha value works more reliable than setting
isOpaque(false)