Java Reference
In-Depth Information
JavaFX-Type-
Expected
Compatible-JavaScript-Type
String
Number
Boolean Array
Object
Yes
Yes
Yes
No
String
Yes
No
No
No
Integer
Yes—with valid
numeric
Yes—float precision lost No
No
Number
Yes—with valid
numeric
Yes—integer converted
to double
No
No
Boolean
Yes—empty string =
false, all others = true
Yes—0 = false, all other
values converted true
Yes
No
Sequence
No
No
No
Yes—with strict type
match on member
values.
Accessing the Scene graph
The JavaFX-JavaScript bridge lets you access the scene graph structure directly from
JavaScript using the js2jfx.stage.scene proxy object (assuming the applet id is
"js2jfx" ). This implies that we could have written our JavaScript to update the content
of the text in the recipe,:
js2jfx.stage.scene.content[0].content = "some text";
The code snippet accesses the first object in the Scene's content sequence which is the
Text object and updates its content to text value.
Accessing JavaScript from JavaFX
Throughout this recipe, we have seen how to interact and control JavaFX from JavaScript.
However, with the Java plugin architecture, it is also possible to do the opposite, where JavaFX
script can access JavaScript code embedded on the web page. To access JavaScript from
JavaFX, you must import the javafx.stage.AppletStageExtension class which, as the
name implies, provides an interaction point between your applet and the JavaFX stage. Using
AppletStageExtension , you can:
F Launch a new web page
F Evaluate JavaScript code
For instance, you can open a new browser window with:
javafx.stage.AppletStageExtension.showDocument("http://www.google.
com/");
Search WWH ::




Custom Search