Java 带有 SVG Salamander 的应用程序 JFrame 不可见

Java application JFrame with SVG Salamander not visibile

我想在 Java 应用程序的主框架中显示我的 SVG 文档。

    mframe = new JFrame();          
    mframe.setBackground(Color.BLACK);
    mframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mframe.setExtendedState(JFrame.MAXIMIZED_BOTH);
    mframe.setUndecorated(true);
    mframe.setMaximumSize(dimMax);
    mgfxdevice.setFullScreenWindow(mframe);

dimMax 已设置并包含:1680x1050

我创建 SVG 文档:

    StringReader srdrSVG = new StringReader(sbSVG.toString());
    URI uriSVG = SVGCache.getSVGUniverse().loadSVG(srdrSVG, SVG_MIMIC);
    msvgPanel = new SVGPanel();
    msvgPanel.setAntiAlias(true);
    msvgPanel.setSvgURI(uriSVG);
    mframe.add(msvgPanel);
    //mframe.pack();
    mframe.setVisible(true);

但是 window 不可见,如果我将光标放在任务栏中的图标上,我会看到空的 window 但没有显示 window。

这里是SVG(StringBuilder sbSVG)的内容:

    <?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" width="1400" height="1050" id="root" style="background-color:#000000"><defs> <linearGradient id="lamp1rim" x1="0" y1="0" x2="1" y2="0"> <stop id="lamp1rimstp0" stop-color="#bfbfbf" offset="0"/> <stop id="lamp1rimstp1" stop-color="#404040" offset="1"/> </linearGradient> <linearGradient id="lamp1cap" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad"> <stop id="lamp1capstp0" stop-color="#00ff00" stop-opacity="0.992188" offset="0"/> <stop id="lamp1capstp1" stop-color="#018201" stop-opacity="0.988281" offset="1"/> </linearGradient> <linearGradient id="lamp1spec" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad"> <stop id="lamp1specstp0" stop-color="#ffffff" stop-opacity="0.996094" offset="0"/> <stop id="lamp1specstp1" stop-color="#06d306" stop-opacity="0.984375" offset="0.703125"/> </linearGradient>  <linearGradient id="lamp2rim" x1="0" y1="0" x2="1" y2="0"> <stop id="lamp2rimstp0" stop-color="#bfbfbf" offset="0"/> <stop id="lamp2rimstp1" stop-color="#404040" offset="1"/> </linearGradient> <linearGradient id="lamp2cap" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad"> <stop id="lamp2capstp0" stop-color="#00ff00" stop-opacity="0.992188" offset="0"/> <stop id="lamp2capstp1" stop-color="#018201" stop-opacity="0.988281" offset="1"/> </linearGradient> <linearGradient id="lamp2spec" x1="0" y1="0" x2="1" y2="1" spreadMethod="pad"> <stop id="lamp2specstp0" stop-color="#ffffff" stop-opacity="0.996094" offset="0"/> <stop id="lamp2specstp1" stop-color="#06d306" stop-opacity="0.984375" offset="0.703125"/> </linearGradient> </defs><g transform="translate(860.0,-16.0) scale(0.25)"> <title id="lamp1title">Lamp 1</title> <circle id="lamp1shroud" cx="320" cy="240" fill="#212121" r="167" stroke-linecap="round" stroke-width="17.5" transform="rotate(90 320 240)"/> <circle id="lamp1outline" cx="319.252837" cy="239.999045" fill="url(#lamp1rim)" fill-opacity="0.64" r="160" stroke-width="17.5" stroke-linecap="round"/> <circle id="lamp1lense" cx="320.000535" cy="240.00169" fill="url(#lamp1cap)" r="150" stroke-linecap="round" stroke-width="17.5"/> <ellipse id="lamp1highlight" cx="249.179609" cy="168.124194" fill="url(#lamp1spec)" rx="75.675959" ry="44.402987" stroke-linecap="round" stroke-width="17.5" transform="rotate(-47.7626 249.18 168.124)"/> <text id="lamp1label" font-family="Verdana" font-size="55pt" text-anchor="middle" x="320" y="260">Lamp 1</text> </g> <g transform="translate(942.0,-16.0) scale(0.25)"> <title id="lamp2title">Lamp 2</title> <circle id="lamp2shroud" cx="320" cy="240" fill="#212121" r="167" stroke-linecap="round" stroke-width="17.5" transform="rotate(90 320 240)"/> <circle id="lamp2outline" cx="319.252837" cy="239.999045" fill="url(#lamp2rim)" fill-opacity="0.64" r="160" stroke-width="17.5" stroke-linecap="round"/> <circle id="lamp2lense" cx="320.000535" cy="240.00169" fill="url(#lamp2cap)" r="150" stroke-linecap="round" stroke-width="17.5"/> <ellipse id="lamp2highlight" cx="249.179609" cy="168.124194" fill="url(#lamp2spec)" rx="75.675959" ry="44.402987" stroke-linecap="round" stroke-width="17.5" transform="rotate(-47.7626 249.18 168.124)"/> <text id="lamp2label" font-family="Verdana" font-size="55pt" text-anchor="middle" x="320" y="260">Lamp 2</text> </g></svg>

要查看上面的 SVG,只需复制到一个新的文本文件中,另存为 'test.svg' 之类的文件,然后在网络浏览器中打开。我在 Firefox 中完全做到了这一点,它呈现得很好,显示了两个绿色的灯。

最终代码,有效:

    //Create panel for the SVG content
    StringReader srdrSVG = new StringReader(sbSVG.toString());
    URI uriSVG = SVGCache.getSVGUniverse().loadSVG(srdrSVG, SVG_MIMIC);
    SVGPanel svgPanel = new SVGPanel();
    svgPanel.setBackground(Color.BLACK);
    svgPanel.setMaximumSize(dimMax);
    svgPanel.setAntiAlias(false);
    svgPanel.setSvgURI(uriSVG);
    //Create application window/container           
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    frame.setUndecorated(true);
    frame.setMaximumSize(dimMax);
    gfxdevice.setFullScreenWindow(frame);
    frame.add(svgPanel);            
    frame.setVisible(true);