简体   繁体   中英

How to Make Transparent SVG Transparent in Java?

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?

我发现设置带有alpha值的背景比设置isOpaque(false)更可靠

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

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