Skip to main content

Embedding JavaFX Problems

2 replies [Last post]
Joined: 2007-12-12


I am trying to embed JavaFX using the JSR223 api, however I have some problems. Given the following Java code:

----- -----

ClassLoader loader = Thread.currentThread().getContextClassLoader();
ScriptEngineManager factory = new ScriptEngineManager(loader);
ScriptEngine engine = factory.getEngineByExtension("fx");

final Bindings b = engine.createBindings();

final ScriptContext sc = new SimpleScriptContext();
sc.setBindings(b, ScriptContext.GLOBAL_SCOPE);
sc.setBindings(b, ScriptContext.ENGINE_SCOPE);


b.put("F:java.lang.String", "F is there");

final FileReader fr = new FileReader("src/net/xeoh/dashboard/fx/Derive.fx");

engine.eval(fr, sc);

Set keySet = b.keySet();
for (String string : keySet) {
System.out.println(string + ": " + b.get(string));


I would expect that

a) F is visible to the Derive.fx script
b) All variables used in the Derive.fx script are available to b

Part of the Derive.FX script looks like this

----- Derive.fx -----

var f:<> = F; // Don't know why
var x = "not there";


But what happens is: F does not seem to be directly visible, for example the sysout(F) like gives an error. However, f does seem to be available and prints out the value of F, which is a bit strange. Also, x does not show up in the bindings.

Can anyone explain this to me ? Also, what would I have to do to make variables to the Java Bindings object ?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-08-07

Try using F:String or F:<>. Constants (and bindings, too) need to be qualified.

The reason you could get away with just F on the

var f:<> = F; // Don't know why

line is because you qualified the left-hand side.


Joined: 2007-12-12

Thanks. But do you also know why the variables are not visible in the bindings-object (i.d., the Java code) ?