Skip to main content

Embedding JavaFX Problems

2 replies [Last post]
eoh
Offline
Joined: 2007-12-12
Points: 0

Hi,

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

----- Test.java -----

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);

engine.setContext(sc);

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);

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

----------------

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
System.out.println(f);
//System.out.println(F);
var x = "not there";
System.out.println(x);

---------

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.
pforhan
Offline
Joined: 2003-08-07
Points: 0

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.

Pat.

eoh
Offline
Joined: 2007-12-12
Points: 0

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