Wednesday, June 27, 2007

Minimal JavaFX Demo

Here are the absolute simplest steps to get a demo of JavaFX up an running:
  1. Download the 3 JavaFX jar files:

    javafxrt.jar
    Filters.jar
    swing-layout.jar


    You can get them from here:

    https://openjfx.dev.java.net/source/browse/openjfx/trunk/lib/

  2. Create a text file called Hello.fx:
    import javafx.ui.*;
    
    Frame {
        content: Label {
            text: "Hello JavaFX"
        }
        visible: true
    }

  3. Add the 3 jars and Hello.fx to your classpath

  4. Run the script like so:

    java net.java.javafx.FXShell Hello

    Note: The name Hello is resolved via the classpath (not the file system).

    Here is how my folders looked:


    ~/DavesJavafxDemo/classes/Hello.fx
    ~/DavesJavafxDemo/lib/javafxrt.jar
    ~/DavesJavafxDemo/lib/Filters.jar
    ~/DavesJavafxDemo/lib/swing-layout.jar


    Thus, my classpath must include the classes folder plus the 3 jar files:


    ~/DavesJavafxDemo/classes
    ~/DavesJavafxDemo/lib/javafxrt.jar
    ~/DavesJavafxDemo/lib/Filters.jar
    ~/DavesJavafxDemo/lib/swing-layout.jar


    Here is the shell script I used:

    cp=./lib/swing-layout.jar:./lib/Filter.jar:./lib/javafxrt.jar:./classes
    java -classpath $cp net.java.javafx.FXShell Hello

    Note: The way I have the paths specified, you must run this script from within DavesJavafxDemo folder.

    On Windows, the shell script (runDemo.bat) would look like this:

    set cp=.\lib\swing-layout.jar;.\lib\Filter.jar;.\lib\javafxrt.jar;.\classes
    java -classpath %cp% net.java.javafx.FXShell Hello

3 comments:

Anonymous said...

Dave,

I don't understand the goal of JavaFX. As a Flash alternative seems limited... JavaFX is not offered as a plug-in (as Flash), and I don't know if it can run as an applet.

On the other hand, how good it is for application development? I have a portal and I would love to put JavaFX on it, but I'm not sure if it would be better than using Flash-oriented tools, such as Laszlo.

Is there a place for JavaFX?

Luis

josh said...

This is cool stuff, Dave. I hope to make your talk tonight.

Anonymous said...

Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!