7 Replies Latest reply: Oct 31, 2012 9:23 AM by 956927 RSS

    Using vector graphics with fxml and JavaFX

    956927
      Hy there,

      i am wondering about using scalable vector graphics, svg, files in my JFX project.
      I know how to show png images with an imageview and can manipulate that via CSS Styling (as fx-background-image)
      But for now i want to add a vector graphic to my scene.
      I am not shure if i should use .svg or .ai or other file formats and how to load that.

      I read about SVGGraph but cannot get the idea behind it
      (and think that this isn't for files)

      So please can anyone tell me how to simple load and show a vector graphic and which format it should take ?

      Ah: A way to make this graphic replaceable via CSS Styling would be nice too ;)

      Thanks,

      BR
        • 1. Re: Using vector graphics with fxml and JavaFX
          MiPa
          JavaFX itself does not provide any means to load some vector graphics from an external source othen than FXML. The problem is that no designer tool is able to create that format directly but it is possible to convert SVG files into FXML.
          Here is a link to such a tool:
          http://tomsondev.bestsolution.at/2012/08/22/svg-to-fxml-converter-as-commandline-util/

          SVGGraph will not be of much help to you because it just handles the portion of an SVG file which defines a path. It is not able to parse a whole SVG file.
          • 2. Re: Using vector graphics with fxml and JavaFX
            956927
            Hy,

            i found the designer tool INKSCAPE and there is an option to export a vector graphic as an .fx File (JavaFX format).
            What is the clue about this ? How can i view this .fx image in javafx ?

            Or should i use png instead.
            Im not shure if there is a resolution loss (quality loss) of the image
            if i scale it.

            BR

            Edited by: 953924 on 21.10.2012 23:26
            • 3. Re: Using vector graphics with fxml and JavaFX
              MiPa
              This .fx file is probably for the old JavaFX 1.x which is not supported anymore for JavaFX 2.x and to my knowledge there is also no converter for that.
              • 4. Re: Using vector graphics with fxml and JavaFX
                956927
                Hy,

                japp thats what i thougth about.
                So is there no simple way to convert my inkscape created .fx vector file for javaFX 2.0 ?

                Or should i use png instead.
                Im not shure if there is a resolution loss (quality loss) of the image
                if i scale it.

                Br

                Edited by: 953924 on 22.10.2012 02:28
                • 5. Re: Using vector graphics with fxml and JavaFX
                  MiPa
                  >
                  So is there no simple way to convert my inkscape created .fx vector file for javaFX 2.0 ?
                  If you still have your original inkscape file you could export to SVG and use the tool I have linked to in my first post.
                  Or should i use png instead.
                  Im not shure if there is a resolution loss (quality loss) of the image
                  if i scale it.
                  Of course there is a quality loss if you use a pixel based image format. Whether this is relevant for you is another question.
                  • 6. Re: Using vector graphics with fxml and JavaFX
                    956927
                    Hy,

                    so i tried tom schindls converter.
                    I did not get a valid fxml file out of this tool.
                    Will get in contact with tom and post a solution here.
                    Maybe that there is a quick solution to do to the tool for me ;)

                    BR
                    • 7. Re: Using vector graphics with fxml and JavaFX
                      956927
                      Hy there,

                      i answered my question with some help of a college:
                      He found the tool : jSimpleX_3.1.jar
                      It can transform svg graphics to a Java FX2.0 compatible fxml file.
                      For shure you need a xslt definition found in : svg2fxml.xsl

                      In SceneBuilder you can add an imageview where you can import the built fxml file.

                      EDIT:
                      You can use Schindels tool to convert, if you save the svg file ex. with Inkscape to normal svg format

                      BR
                      from Austria

                      Edited by: 953924 on 31.10.2012 07:22