JavaFX – SVGPath


We recently celebrated Holi – Festival of Colours.
It was real fun! Now lets try to celebrate Holi with JavaFX!.

You can create an SVG path in JavaFX using SVGPath class. It accepts content which is a string formatted as specified here.


SVGPath {
    content: "M48.859,43.518c8.424,17.64,2.736,140.832-7.128,184.032"
             "c-9.864,43.272-19.728,98.28-22.032,144.576c-1.008,19.728,"
             "2.016,27.504,14.904,27.504c22.752,0,51.624-47.952,87.84-46.872"
             "c36.288,1.08,47.808,55.008,64.8,54.648c16.992-0.36,30.672-6.264,"
             "30.816-58.752C218.563,191.981,87.235,64.973,48.859,43.518"
             "L48.859,43.518L48.859,43.518L48.859,43.518z"
    fill: Color.BLACK
}

We can combine a series of SVGPath to create the final image. Now we can manipulate attributes of individual SVGPath such as fill, stroke, strokeWidth etc. I’m using the same ColorChooser code as in previous post.

For Applet mode, click on above image

For standalone mode

To paint Duke select any part of Duke and then select a color from color chooser.
Now you can play Holi with Duke! Have fun!

Source

var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_svgpath”;
var dzone_style = ‘2’;

Advertisements

About Rakesh Menon
-

7 Responses to JavaFX – SVGPath

  1. Vaibhav says:

    Very nice. I am not able to deselect it. Is it possible to deselect on next click because that selected line, not allow me to see the duke nicely with other colors.

  2. Farrukh Obaid says:

    Nice demo
    Please check my demo i created in JavaFX my first Demo on my website
    "www.jfxstudio.741.com"
    i will enhance this demo to complete website in JavaFX ur help will be needed

  3. Rakesh Menon says:

    @Vaibhav Thanks! Added toggle selection

  4. Rakesh Menon says:

    @Farrukh Thatz cool! Great start.. ‘ll definitely help you.

  5. Farrukh Obaid says:

    thanks Rakesh
    Questions
    1) how to embed True Type Font(ttf) in JavaFX
    i think we can embed in FXZ format by using
    Font.fontFromURL(path,size) i check this works but i want to use in normal fx file it is not working..
    2) first time we see applet it chached in the system i update file and upload again "with the same name" when i browse applet it load previoud version in order to see new one i delete the file from cache is there any method to tackle this…

  6. Rakesh Menon says:

    @Farrukh (1) I think its not supported, I didn’t find any public APIs. Yes, there are some internal APIs, but that is not recommended. I’ll confirm this and get back to you. (2) By default the cache system depends on timestamp, so ideally it must load the new jar after few minutes. This is not reliable, also may fail on slow network. The check times out after few seconds. You need to use versioning for reliable mechanism.
    http://java.sun.com/javase/technologies/desktop/javawebstart/reference/techart/index.html

  7. Rakesh Menon says:

    @Farrukh Thanks for your question. I have a new post on how to use ttf font – http://blogs.sun.com/rakeshmenonp/entry/javafx_custom_fonts

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: