Skip to main content

Using JavaFX in Swing ?

8 replies [Last post]
stanhirsh
Offline
Joined: 2008-08-01
Points: 0

Hi there,

is it possible to use (compiled) components written in javafx in an existing swing application ?

Thanks, Stan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stanhirsh
Offline
Joined: 2008-08-01
Points: 0

Hi Michael,

following your example, how would one be able to create an instance of MyJavaFXClass in a java class?

Thanks, Stan

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Basically there are three options (of which one does not work yet and one is not recommended): :-)
1) Use the JavaFXScriptEngine. The article explains it only briefly, but there are some links at the bottom.
2) Use reflection. AFAIK the JavaFX-reflection API is not done yet, but it is planned for the next milestone (early September).
3) Use the Java-constructor created during compilation of the JavaFX class. Although this is possible, I do not recommend it. The compiled code it is an implementation detail, which might change in the future.

Michael

alexsch
Offline
Joined: 2007-07-12
Points: 0

It had been possible to create a ComponentWidget class in old JavaFX Script
which had getJComponent() function. Why something like this is not implemented in the current UI library?

stanhirsh
Offline
Joined: 2008-08-01
Points: 0

... marked as unanswered since some additional questions occured (look further up :-)

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0
stanhirsh
Offline
Joined: 2008-08-01
Points: 0

Hi Michael,

thanks for replying - after reading your article I think that the interfaces approach would suit my needs most, but does it also work on more complex components ? The following article http://stufffromjim.blogspot.com/2008/05/compiled-javafx-in-swing-applic... suggests that this is not trivial. What would be the best way to deal with a complex jfx component ?

Thanks, Stan

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

Hmmm, I cannot really tell, what the problem of the author was, because the exception is not shown completely. It's a pretty old article, a lot of bugs in the compiler have been fixed since then.

I usually use the interface approach and so far it worked very well. If you have problems, just post them here and you'll get help.

stanhirsh
Offline
Joined: 2008-08-01
Points: 0

OK, Thanks :-), I´ll try this way.

Stan