3

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?

dieend
  • 2,231
  • 1
  • 24
  • 29
  • `transparnet.png`? Why are you using a png file there? SVG or PNG? – J-16 SDiZ Aug 30 '11 at 07:30
  • That is to make the scroll pane transparent. It is kind of work around. What I wanted to make transparent is the canvasDiagram. I've edited so it might be clearer – dieend Aug 30 '11 at 08:08
  • "Is it the fault in the XML definition?" For me, this sounds like a fault in Java. BTW: [Don't include a DOCTYPE declaration](https://jwatt.org/svg/authoring/#doctype-declaration) – feeela Aug 30 '11 at 09:46
  • So its the Java, eh? I will remove the XML tag. Okay. I will delete all DTD in my SVG. Thanks. – dieend Aug 30 '11 at 10:19

1 Answers1

1

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

setBackground(new Color(0,0,0,0));
Joost
  • 3,169
  • 2
  • 22
  • 40