This discussion is archived
8 Replies Latest reply: Aug 9, 2012 9:44 PM by DrClap RSS

Vector Images in Java

949976 Newbie
Currently Being Moderated
Hi,


I want to use vector images in my code.This is because I've used raster images(.png) previously in my code inorder to set the icon for my jlabel.

When I work in high resolution monitor, the images are not resizing properly.


So, I want to convert raster images to vector images and then I want to use those images in my jlabel.

So, pls tell me how to convert raster image to vector image and how to use the vector image in my jlabel.


Thanks in advance,

M.Sivapreeya
  • 1. Re: Vector Images in Java
    rukbat Guru Moderator
    Currently Being Moderated
    Show us how you have used Java programming code to attempt this and you might get a response from someone to assist you getting the code to a better form.

    If you do get around to paste your code into a reply, be sure you use
    code tags, just like you learned from reading the OTN forum's FAQ page.
    (link is at the top corner of every forum page)
  • 2. Re: Vector Images in Java
    949976 Newbie
    Currently Being Moderated
    I was using like this previously,

    Jlabel jlblText = new JLabel();

    jlblText.setIcon(new ImageIcon(getClass().getResource("/Resources/image.png"));


    And, it worked.


    The same way,I tried for .svg as given below.

    Jlabel jlblText = new JLabel();

    jlblText.setIcon(new ImageIcon(getClass().getResource("/Resources/image.svg"));

    And,it didn't work!
  • 3. Re: Vector Images in Java
    gimbal2 Guru
    Currently Being Moderated
    No, Java has no built in support for SVG files (at least Swing/ImageIO doesn't).
  • 4. Re: Vector Images in Java
    rp0428 Guru
    Currently Being Moderated
    Welcome to the forum!
    >
    I want to use vector images in my code.This is because I've used raster images(.png) previously in my code inorder to set the icon for my jlabel.
    >
    You will need to use a 3rd party library to use SVG. Here is an Oracle Sun Developer article from several years ago - included because it is from Oracle.
    http://java.sun.com/developer/technicalArticles/GUI/svg/

    There are other more recent offerings on the web. Here is a simple one that illustrates it
    http://plindenbaum.blogspot.com/2009/07/simple-java-based-svg-renderer.html

    Couldn't find a specific example for JLabels.
  • 5. Re: Vector Images in Java
    gimbal2 Guru
    Currently Being Moderated
    rp0428 wrote:
    Couldn't find a specific example for JLabels.
    Uh, that last link you provided is exactly an example on how to use it with a JLabel :) Mission accomplished dude.
  • 6. Re: Vector Images in Java
    949976 Newbie
    Currently Being Moderated
    Hi,



    Thanks a lot for ur reply.

    But,I'm a java beginner and I'm unable to get the stuff clearly in the blog that u've suggested.

    So, pls tell me how to set the .svg image as icon for the jlabel in java without using any 3rd party tool.
  • 7. Re: Vector Images in Java
    DrClap Expert
    Currently Being Moderated
    Can't be done by a beginner. You will have noticed (or should have noticed) that the person who does know how to do it required several hundred lines of code and a long list of supporting classes. So rejecting that expertise and asking for something simple is rather absurd.
  • 8. Re: Vector Images in Java
    rp0428 Guru
    Currently Being Moderated
    >
    But,I'm a java beginner and I'm unable to get the stuff clearly in the blog that u've suggested.
    >
    Did you download,compile and try the source code and example from the link?

    Let me guess - NO. Am I right?

    The best way to learn is to actually do it. You have a link. It has source code. It has an example. Download the source code, compile it and try the example.

    Don't bother asking for more help if you aren't willing to make an effort yourself.
    >
    So, pls tell me how to set the .svg image as icon for the jlabel in java without using any 3rd party tool.
    >
    We already gave you the answer to that. As already said above
    >
    You will need to use a 3rd party library to use SVG.
    >
    You can choose to believe it or not. That is your choice. You ask a question. You got the answer. Deal with reality.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points