Java +Batik +SVG

Discussion in 'Java' started by Christian-Josef Schrattenthaler, Jul 8, 2006.

  1. Hi!

    I want to use SVG images in my Java application. I only need to display
    some images, nothing other is to do!

    The only powerful API I found was Batik.

    I searched and tried many hours, but I didn't find an easy way to display
    my SVG images in my JFrames, JDialogs, ...

    Please, can anyone give me a hint?

    Thanks and kind greetings,
    Christian.
    Christian-Josef Schrattenthaler, Jul 8, 2006
    #1
    1. Advertising

  2. Christian-Josef Schrattenthaler

    Oliver Wong Guest

    "Christian-Josef Schrattenthaler" <> wrote in message
    news:1hy9687uzh9qx.nbpuc123svww$...
    > Hi!
    >
    > I want to use SVG images in my Java application. I only need to display
    > some images, nothing other is to do!
    >
    > The only powerful API I found was Batik.
    >
    > I searched and tried many hours, but I didn't find an easy way to display
    > my SVG images in my JFrames, JDialogs, ...
    >
    > Please, can anyone give me a hint?


    http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/swing/svg/AbstractJSVGComponent.html

    - Oliver
    Oliver Wong, Jul 10, 2006
    #2
    1. Advertising

  3. Hi Oliver!

    > http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/swing/svg/AbstractJSVGComponent.html


    Sorry, but I am a Java-Newbie, and I didn't get this to work.

    At this time, I can display a svg image over the JSVGCanvas:

    ***
    JSVGCanvas jsvgc = new JSVGCanvas();
    jsvgc.setURI(new File("CJSCardIndexLogo.svg").toURI().toString());
    jsvgc.setPreferredSize(new Dimension(300, 300));
    add(jsvgc);
    ***

    This is ok, but I also need to use this svg image as IconImage for my
    JFrame. Do you have a solution for this?

    Greetings,
    Christian.
    Christian-Josef Schrattenthaler, Jul 11, 2006
    #3
  4. Christian-Josef Schrattenthaler

    Oliver Wong Guest

    "Christian-Josef Schrattenthaler" <> wrote in message
    news:ks8jitzqw159$.erb0z8yk8he4$...
    > Hi Oliver!
    >
    >> http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/swing/svg/AbstractJSVGComponent.html

    >
    > Sorry, but I am a Java-Newbie, and I didn't get this to work.
    >
    > At this time, I can display a svg image over the JSVGCanvas:
    >
    > ***
    > JSVGCanvas jsvgc = new JSVGCanvas();
    > jsvgc.setURI(new File("CJSCardIndexLogo.svg").toURI().toString());
    > jsvgc.setPreferredSize(new Dimension(300, 300));
    > add(jsvgc);
    > ***
    >
    > This is ok, but I also need to use this svg image as IconImage for my
    > JFrame. Do you have a solution for this?
    >
    > Greetings,
    > Christian.


    The page I linked to has 5 phases. Which phase did you get stuck at?

    - Oliver
    Oliver Wong, Jul 12, 2006
    #4
  5. Hi Oliver!

    > The page I linked to has 5 phases. Which phase did you get stuck at?


    I want to use the svg graphic as an java.awt.Image. For Example to use in
    'setIconImage("mygraphic.svg")' for the Icon of a JFrame.

    I tried:

    ***
    final JSVGComponent svgComp = new JSVGComponent();
    svgComp.loadSVGDocument("CJSCardIndexLogo.svg");
    setIconImage(svgComp);
    ***

    But svgComp is not an Image, and I can't cast it to an Image.

    I found no information about using an svg graphic under Java as an Image.

    Can you tell me how to do?

    Greetings,
    Christian.
    Christian-Josef Schrattenthaler, Jul 12, 2006
    #5
  6. Christian-Josef Schrattenthaler

    Oliver Wong Guest

    "Christian-Josef Schrattenthaler" <> wrote in message
    news:tevwd2tcvmd9.1k07572fpcc4m$...
    > Hi Oliver!
    >
    >> The page I linked to has 5 phases. Which phase did you get stuck at?

    >
    > I want to use the svg graphic as an java.awt.Image. For Example to use in
    > 'setIconImage("mygraphic.svg")' for the Icon of a JFrame.
    >
    > I tried:
    >
    > ***
    > final JSVGComponent svgComp = new JSVGComponent();
    > svgComp.loadSVGDocument("CJSCardIndexLogo.svg");
    > setIconImage(svgComp);
    > ***
    >
    > But svgComp is not an Image, and I can't cast it to an Image.
    >
    > I found no information about using an svg graphic under Java as an Image.
    >
    > Can you tell me how to do?


    Previously, you said you wanted to display an SVG image within a JFrame.
    Now you're saying you want to convert it to an Image object somehow. Which
    is it that you actually want to do? The solution for each will probably be
    vastly different.

    - Oliver
    Oliver Wong, Jul 12, 2006
    #6
  7. Hello Oliver!

    > Previously, you said you wanted to display an SVG image within a JFrame.
    > Now you're saying you want to convert it to an Image object somehow. Which
    > is it that you actually want to do? The solution for each will probably be
    > vastly different.


    Till now I used JPG images for the Icon of a JFrame, for the Icon of a
    JLabel, to display a graphic in a frame, and so on.

    But vector graphics are better than pixel graphics, if you want to resize
    them without losing quality, and SVG images are the future of vector
    graphics. I searched also for a solution for EPS images, but I didn't find
    anything.

    I know how to display an image in a frame over JSVGCanvas. It's quit
    simple, if you know that you have to use JSVGCanvas for this.

    But now I want also replace my JPG images with my new SVG images for:
    JFrame.setIconImage(Image) and JLabel.setIcon(Image).

    Do you knwo how I can do this? Is it possible to create an Image Object
    from an SVG image to use it with setIconImage() and setIcon()?

    Thanks and kind greetings,
    Christian.
    Christian-Josef Schrattenthaler, Jul 12, 2006
    #7
  8. Christian-Josef Schrattenthaler

    Oliver Wong Guest

    "Christian-Josef Schrattenthaler" <> wrote in message
    news:...
    > Hello Oliver!
    >
    >> Previously, you said you wanted to display an SVG image within a JFrame.
    >> Now you're saying you want to convert it to an Image object somehow.
    >> Which
    >> is it that you actually want to do? The solution for each will probably
    >> be
    >> vastly different.

    >
    > Till now I used JPG images for the Icon of a JFrame, for the Icon of a
    > JLabel, to display a graphic in a frame, and so on.
    >
    > But vector graphics are better than pixel graphics, if you want to resize
    > them without losing quality, and SVG images are the future of vector
    > graphics. I searched also for a solution for EPS images, but I didn't find
    > anything.
    >
    > I know how to display an image in a frame over JSVGCanvas. It's quit
    > simple, if you know that you have to use JSVGCanvas for this.
    >
    > But now I want also replace my JPG images with my new SVG images for:
    > JFrame.setIconImage(Image) and JLabel.setIcon(Image).
    >
    > Do you knwo how I can do this? Is it possible to create an Image Object
    > from an SVG image to use it with setIconImage() and setIcon()?
    >
    > Thanks and kind greetings,
    > Christian.


    for JFrame.setIconImage(Image), the icon is likely to be no bigger than
    128 by 128 pixels on all the OSes that I know of. I believe that on Windows,
    it may be as small as 32x32. In this case, use a 128x128 JPG, and you'll be
    set for the next 5 years.

    For JLabel.setIcon(Image), I recommend you use an AbstractJSVGComponent,
    and position it relative to your label using a layout manager.

    - Oliver
    Oliver Wong, Jul 12, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian K
    Replies:
    0
    Views:
    831
    Brian K
    Oct 12, 2003
  2. Gemmel
    Replies:
    0
    Views:
    408
    Gemmel
    Sep 4, 2004
  3. Arne Nordmann
    Replies:
    0
    Views:
    515
    Arne Nordmann
    Jun 28, 2004
  4. Mardagg
    Replies:
    0
    Views:
    796
    Mardagg
    May 12, 2006
  5. Mardagg
    Replies:
    0
    Views:
    649
    Mardagg
    May 12, 2006
Loading...

Share This Page