Java +Batik +SVG

  • Thread starter Christian-Josef Schrattenthaler
  • Start date
C

Christian-Josef Schrattenthaler

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.
 
O

Oliver Wong

C

Christian-Josef Schrattenthaler

Hi Oliver!

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.
 
O

Oliver Wong

Christian-Josef Schrattenthaler said:
Hi Oliver!


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
 
C

Christian-Josef Schrattenthaler

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.
 
O

Oliver Wong

Christian-Josef Schrattenthaler said:
Hi Oliver!


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
 
C

Christian-Josef Schrattenthaler

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.
 
O

Oliver Wong

Christian-Josef Schrattenthaler said:
Hello Oliver!


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top