Sundararajan's Weblog

Standalone JavaFX FXML app with nashorn scripts for event handling - no java code!

In nashorn openjdk repository http://hg.openjdk.java.net/jdk9/dev/nashorn,
there is a script called "fxmlrunner.js" in the "samples" directory. This script can accept any FXML file as command line argument and "run it". If that FXML file has event handlers written in (nashorn) javascript, then we can have complete runnable application without having to write any Java code!

When I came across this FXML example https://github.com/halcat0x15a/calculator/blob/master/src/calculator/calculator.fxml, I wanted to replace Java event handling + actual calculator implementation with nashorn scripts. The "ported" FMXL+nashorn script app. uses nashorn scripts for action handlers and uses "eval" to implement calculator back-end.

Calculator App in FXML + nashorn scripts

Download these files:
Now, you can the app with the following command:

jjs -fx fxmlrunner.js -- calc.fxml

You should see a calculator app window that looks like this:

Join the discussion

Comments ( 3 )
  • Specto IT Training Monday, October 5, 2015

    www.oracleonlinetraining.com is providing Oracle APPS Functional and Technical training contact us:+91-9533456356,

    by real time experts in USA,UK,Canada,Australia.

    Oracle apps finance online training,oracle Apps SCM online training,Oracle apps technical online training,oracle Apps 11g online training,Oracle apps manufacturing training,

    Oracle Apps Supply Chain Management training.

    Forfull course details please visit our website http://oracleonlinetraining.com/

  • Dusty Monday, October 12, 2015

    I'm unable to start the example, I get this error:

    Caused by: jdk.nashorn.internal.runtime.ParserException: fxmlrunner.js:1:0 Expected an operand but found <

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

  • sundar Monday, October 12, 2015

    If you did a "save" on that fxmlrunner.js link, most likely you got a HTML file back from the openjdk server. I suggest you view the fxmlrunner.js script in your browser and cut-paste the content as a text file.

Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.