开发者

How to Make Transparent SVG Transparent in Java?

开发者 https://www.devze.com 2023-03-31 11:27 出处:网络
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

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?


I found that setting a background with alpha value works more reliable than setting isOpaque(false)

setBackground(new Color(0,0,0,0));
0

精彩评论

暂无评论...
验证码 换一张
取 消