Geertjan's Blog

  • March 28, 2015

Combining Nashorn Scripting with JavaFX

Geertjan Wielenga
Product Manager

Following from yesterday's blog entry, the question I had was: "Can I use -scripting and -fx at the same time?"

The answer is yes:

 /* global $OUT, generator, FXCollections, javafx, $STAGE */
var output = $OUT;
var cleanedOutput = [];
output = output.substring(81, output.length - 553).split("\n");
for each(generator in output){
    if (generator.length>0){
options = FXCollections.observableArrayList(cleanedOutput);
selectedGenerator = new Label();
comboBox = new ComboBox(options);
comboBox.valueProperty().addListener(new javafx.beans.value.ChangeListener({
    changed: function (observableValue, oldSelection, newSelection) {
var root = new VBox(10);
var box1 = new HBox(10);
var box2 = new HBox(10);
box1.children.addAll(new Label("Choose a generator: "), comboBox);
root.children.addAll(box1, box2);
$STAGE.title = "Yeoman Generator";
$STAGE.scene = new Scene(root, 280, 100);

The above runs Yeoman on the command line via JavaScript, thanks to Nashorn, and displays the result in JavaFX:

And this is how the code above looks in NetBeans:

Indeed, this would appear to be the start of a shell script enabling Yeoman to be used from JavaFX.

By the way, to do the above, and to use the info in Adam's recent screencast and in my blog entry from yesterday, you need a NetBeans development build and then use the Nashorn tab that has been introduced there, i.e., this is not in NetBeans IDE 8.0.2 but in a development build for the next release:

Join the discussion

Comments ( 3 )
  • Chris Monday, March 30, 2015

    Is it possible, with such technic, to create plugins for Netbeans with JavaScript too? That would be so easy as with Cordova to create Plugins with HTML5, JS and CSS and wrap it around with a web view to get access to the netbeans api or like the example above.



  • Geertjan Monday, March 30, 2015

    Hi Chris, that's exactly what I've been looking at, here: https://blogs.oracle.com/geertjan/entry/extending_netbeans_with_nashorn

  • Chris Monday, March 30, 2015

    Hi Geertjan,

    nice, I will have a look at it soon :).



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