Search code examples
svgjavafxyfiles

How do I use SVG images as node styles with yFiles for JavaFX?


I need to style nodes with SVG images but cannot make it work. I am using ImageNodeStyle and passing an SVG image to the constructor. However, applying this style to nodes has no effect. I tried using bitmap images and they work fine.

How do I enable SVG image support for node styling?


Solution

  • yFiles for JavaFX uses JavaFX as the rendering engine and JavaFX unfortunately does not directly support SVG images. You need to convert the SVG image into an image that JavaFX understands and then you will be able to use it with ImageNodeStyle.

    Using WebViews would be another option, however this is a very heavyweight solution that does not scale very well for many SVGs. You can surely use for rendering a background SVG, but I would not use hundreds of instances to show simple SVG graphics for the visualization of nodes.

    Take a look at this answer to a related SVG/JavaFX question: it proposes a solution to the generic problem, which should also work for this specific issue.