Skip to main content

programatically invoking a JavaFX script

8 replies [Last post]
jryog69
Offline
Joined: 2008-02-15

I am attempting to return a BorderPanel using the JSR-223 Script Engine. I have a Java Class named FxScriptLauncher (see http://jfx.wikia.com/wiki/Programmatically_invoking_a_JavaFX_Script).

I am able to recreate the example on that page, where I am able to return a FX class, but when I try and return a BorderPanel as the content for the Frame of another FX class, I does not return anything.

Here is the line when I try and bind it to the content:

content: bind (Widget) FxScriptLauncher.main("BPCloseOut_1.fx")

I think it may be an issue with me casting it as a Widget. Is casting supported in JavaFx? I am casting it because it is just returning an object. It is probably because I am trying to upcast it. Does anyone have any idea how I can fix this?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pdizzyd
Offline
Joined: 2008-05-08

The code works in 6.1 with the latest plugin, the code editor doesn't allows "see" the FX files but it builds fine.

Thanks for the code.

Message was edited by: pdizzyd

jryog69
Offline
Joined: 2008-02-15

Using the example, I am getting an error on function. I am using NetBeans 6.01 and I get an error on "public function composeWidget():Widget{" .

It does not like the "{" because I get the message "Encountered { at line 16, column 43. Was expecting one of: "*"...etc

Any ideas what may be wrong?

alexsch
Offline
Joined: 2007-07-12

Do you use a compiler version of JavaFX Script plugin?
http://javafx.netbeans.org/download-compiler-JFXplugin.html

jryog69
Offline
Joined: 2008-02-15

Yes. I have tried it in NetBeans 6.01 initially, and have tried it in NetBeans 6.1 with the compiler version of the JavaFX plugin and get the error as follows:

../MyPanel2/MyPanel2.fx:15: cannot find symbol
symbol : variable MyPanel2
location: class MyPanel2.MyPanel2

alexsch
Offline
Joined: 2007-07-12

> Yes. I have tried it in NetBeans 6.01 initially, and
> have tried it in NetBeans 6.1 with the compiler
> version of the JavaFX plugin and get the error as
> follows:
>
>
> ../MyPanel2/MyPanel2.fx:15: cannot find symbol
> symbol : variable MyPanel2
> location: class MyPanel2.MyPanel2

Could you post your code. It helps to investigate the problem.

jryog69
Offline
Joined: 2008-02-15

I think it is a problem with my Netbeans. I have verified it works with pdizzyd (we are at the same location)

alexsch
Offline
Joined: 2007-07-12

You can use compiler version of JavaFX Script language to directly instantiate FX objects in Java code.

You can put Widget component on JFrame using [b]getComponent()[/b] method.
For example:

[code]
// -------------------------------- MyPanel.fx ------------------------------------
import javafx.ui.*;

public class MyPanel extends CompositeWidget{
public function composeWidget():Widget{
return BorderPanel{
center: Label{ text: "Hello World!"}
}
}
}
// -------------------------------- MyFrame.java ------------------------------------
import javax.swing.JFrame;
import javax.swing.JComponent;

public class MyFrame extends JFrame {

public MyFrame() {
setSize(300, 300);
JComponent myPanel = (new MyPanel()).getComponent();
getContentPane().add(myPanel);
}

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { new MyFrame().setVisible(true); }
});
}
}
[/code]

pdizzyd
Offline
Joined: 2008-05-08

So if we are trying to build a Java app using FX but want to build a Widget factory, would it make more sense to start with a Swing Frame and populate it with FX rather than the other way around?

Thanks for any suggestions.