Results 1 to 8 of 8
  1. #1
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default paint in vector graphics

    Hi,

    I want to make a vector graphics with Java.
    I already make an GUI with some JPanel there and I have write a paint method for the Graphics using Graphics2D.
    But since the Quality of the Graphics is not as expected, we want to change the paint method through vector graphics.
    Since Im still a newbie in Java, Ive googled for this vector graphics possibilities with Java, and Batik is as far as I can find.
    But as far as I concerned, with Batik I cannot draw on the JPanel, which I already have.

    So.... Are there any other possibilities to draw vector graphics other than Batic?
    Or have anyone use batik and can give me some example to paint with it on a JPanel?

    thanks for any help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by koddy View Post
    ....But as far as I concerned, with Batik I cannot draw on the JPanel, which I already have.

    So.... Are there any other possibilities to draw vector graphics other than Batic?
    Or have anyone use batik and can give me some example to paint with it on a JPanel?
    But AFAIK, Batik can draw on a JSVGCanvas object which derives from JComponent, so this should be easily usable form within a Swing application.

    The Batik api can be found here: Apache Batik Javadoc

  3. #3
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    So... I wanna try it, but when I read the data (since I need to read the xml-data first for the input), I got error message:

    <code>
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/batik/svggen/SVGGraphics2D
    <code>

    But when Im not using any batik api, the program run smoothly.

    Does anyone know, what that error message mean? And how to fix it?
    Thank you in advance.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Do you have the Batik jar file(s) in your class path, or if you're using an IDE, are they in the project's compile path?

  5. #5
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    yo... Ive already downloaded the Batik jar files and compile it in the project library

  6. #6
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    I post the error code, which I get when I run the program.

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/batik/svggen/SVGGraphics2D
    
            at EvaluateDataModel.<init>(EvaluateDataModel.java:27)
            at DataModel.createEvaluateDataModel(DataModel.java:52)
            at Controller$LoadXMLFileListener.actionPerformed(Controller.java:151)
            at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
            at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
            at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
            at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
            at javax.swing.plaf.basic.BasicButtonListener$Actions.actionPerformed(BasicButtonListener.java:287)
            at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1636)
            at javax.swing.JComponent.processKeyBinding(JComponent.java:2849)
            at javax.swing.JComponent.processKeyBindings(JComponent.java:2884)
            at javax.swing.JComponent.processKeyEvent(JComponent.java:2812)
            at java.awt.Component.processEvent(Component.java:5993)
            at java.awt.Container.processEvent(Container.java:2041)
            at java.awt.Component.dispatchEventImpl(Component.java:4583)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Component.dispatchEvent(Component.java:4413)
            at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1848)
            at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:704)
            at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:969)
            at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:841)
            at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:668)
            at java.awt.Component.dispatchEventImpl(Component.java:4455)
            at java.awt.Container.dispatchEventImpl(Container.java:2099)
            at java.awt.Window.dispatchEventImpl(Window.java:2475)
            at java.awt.Component.dispatchEvent(Component.java:4413)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Caused by: java.lang.ClassNotFoundException: org.apache.batik.svggen.SVGGraphics2D
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
            ... 33 more
    The program running smoothly without BATIK. But when I insert BATIK for SVG Graphics, I got the error code like these.
    What I cannot understand, I got the error when it still on the step of reading the XML-Data (since I need to read the Datas for the Graphics) and it hasnt ever gone to class and method for the drawing graphics.

    I try to re-download the BATIK and reinstall and recompile the BATIK files jar to the project, but it still got the same error.

    Has anyone any idea?
    Thank you very much.

  7. #7
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    well... the problem before is solved... but now I have another problem.

    so.. the code I write on JSVGCanvas is:
    Java Code:
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = impl.createDocument(svgNS, "svg", null);
    SVGGraphics2D svgGraphics = new SVGGraphics2D(doc);
    EvaluateDrawing drawing = new EvaluateDrawing(dataModel.getGDSDataModel());
    Element root = doc.getDocumentElement();
    svgGraphics.getRoot(root);
    canvas1.setSVGDocument(doc);
    but when I compile it, I got the error code like this:
    PHP Code:
    setSVGDocument(org.w3c.dom.svg.SVGDocument) in org.apache.batik.swing.svg.AbstractJSVGComponent cannot be applied to (org.w3c.dom.Document)
                    canvas1.setSVGDocument(doc);
    Can anyone help me, what should I do?

    Thank you very much

  8. #8
    koddy is offline Member
    Join Date
    Apr 2010
    Posts
    20
    Rep Power
    0

    Default

    Hallo,

    since I still dont know the answer of the problem before, I try to make it another way to paint in vector graphics.
    I can now make the vector graphics in svg and I save the svg file first.
    After that, I read the file again on my JSVGCanvas (canvas1), which is on the panel, to show the graphic.

    Since I use Netbeans for the IDE, I must override the paint-methode to show the graphic.

    Here is the code.
    Java Code:
    panel =  new JPanel (){
        public void paint(Graphics g) {
                super.paint(g);
                panel.setOpaque(true);
                panel.add(canvas1);
                canvas1.setURI(new File("ProfilRight.svg").toURI().toString());
                canvas1.repaint();
            }
        }
    But when I compile the program, I get an endlose run of this paint method, so that the graphic wont be displayed.

    Can anyone help me, how I can correct the code?

    Thank you very much in advance for any help...

Similar Threads

  1. Two JPanels and paint(Graphics)
    By ingfy in forum New To Java
    Replies: 3
    Last Post: 04-27-2010, 08:51 PM
  2. Vector<vector> loop thru
    By ocean in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:17 PM
  3. Some confusions with paint()
    By kendaop in forum Java Applets
    Replies: 1
    Last Post: 01-24-2009, 12:23 AM
  4. finished paint!
    By diggitydoggz in forum New To Java
    Replies: 3
    Last Post: 01-04-2009, 10:33 AM
  5. print variable with paint(Graphics g) ??
    By tghn2b in forum New To Java
    Replies: 10
    Last Post: 12-29-2008, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •