I am trying to reproduce this example , which should create an emoticon image using the SVGSalamander API. However, when I run my program, the image does not appear. There is only the main JFrame. Some of the syntaxes should have been different due to the generated code using NetBeans. Unfortunately, I canβt change the generated code. Does anyone have an idea of ββwhat changes I need to make to run the example? The only difference in my code is the generated part of the initComponents () method.
This is my code:
class IconPanel extends javax.swing.JPanel { public static final long serialVersioUID = 0; final SVGIcon icon; public IconPanel() { StringReader reader = new StringReader(makeDynamicSVG()); URI uri = SVGCache.getSVGUniverse().loadSVG(reader, "myImage"); icon = new SVGIcon(); icon.setSvgURI(uri); setPreferredSize(new Dimension(400, 400)); } @Override public void paintComponent(Graphics g) { final int width = getWidth(); final int height = getHeight(); g.setColor(getBackground()); g.fillRect(0, 0, width, height); icon.paintIcon(this, g, 0, 0); } private String makeDynamicSVG() { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); pw.println("<svg width=\"400\" height=\"400\" style=\"fill:none;stroke-width:4\">"); pw.println(" <circle cx=\"200\" cy=\"200\" r=\"200\" style=\"stroke:blue\"/>"); pw.println(" <circle cx=\"140\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>"); pw.println(" <circle cx=\"260\" cy=\"140\" r=\"40\" style=\"stroke:red\"/>"); pw.println(" <polyline points=\"100 300 150 340 250 240 300 300\" style=\"stroke:red\"/>"); pw.println("</svg>"); pw.close(); return sw.toString(); } } public class MainFrame extends javax.swing.JFrame { public static final long serialVersionUID = 0; IconPanel panel = new IconPanel(); public MainFrame() { initComponents(); this.getContentPane().add(panel, BorderLayout.CENTER); pack(); } @SuppressWarnings("unchecked")
java svg
user1028408
source share