2
我想用這個簡單的代碼在JPanel上加載SVG文件,但JPanel是灰色的。我有什麼問題嗎?用蠟染加載JPanel上的SVG文件
import javax.swing.*;
import org.apache.batik.swing.JSVGCanvas;
public class SVGApplication extends JPanel
{
public SVGApplication(){
JSVGCanvas svg = new JSVGCanvas();
// location of the SVG File
svg.setURI("file:/C:/Users/Linda/Desktop/test.svg");
JPanel panel = new JPanel();
panel.add(svg);
}
public static void main(String[] args)
{
JFrame frame = new JFrame("SVGView");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new SVGApplication());
frame.pack();
frame.setSize(500, 400);
frame.setVisible(true);
}
}