How to wrap a swing component in a javaFX 2.0 application - java

The ability to wrap a swing component in a javaFX application seems to have vanished from javaFX 2:
javafx.ext.swing.SwingComponent
is not there any more in javaFX 2 beta API.
Is there still a way to do this in the new API?

SwingNode class is used to embed a Swing content into a JavaFX application.
Here is the link.

There is 3rd-party support library, see http://rkennke.wordpress.com/2011/11/16/swing-in-javafx-demo/

According to this issue on the FX 2.0 JIRA they aren't planning to support it in the initial release of FX 2.0. There's also no promise that they will do it down the road.
http://javafx-jira.kenai.com/browse/RT-12100

It seems that since javafx 2.0+, we can't embed Swing component into JavaFX (vice versa is possible, using JFXPanel class), detail in this link:
https://forums.oracle.com/forums/thread.jspa?threadID=2364553&tstart=0
I accidentally found this link when trying to embed Swing Calendar view component into JavaFX 2.0 application (which I suppose it's possible at the beginning).

Related

What new changes came with Swing in Java 8?

Are there any changes than came with Swing and AWT in Java 8? In release notes for Java 8 I it's not mentioned.
I don't think so...
Swing has really old API, oracle left it behind in favor of JavaFX - which does have (and still developed) methods that use the new APIs.
Edit: just remembered, the only new 'feature' that I know of that was added to swing is the JFXPanel which is a way of integrating JavaFX components into your app swing-fx-interoperability

Can JavaFX be included on a Java SE project?

I'm trying to create an Inventory project and have graphs on it. I'd like the graph to be created thru JavaFX and call it on a Java main class. Is it possible to add a JavaFX class to a Java project?
I'm using netbeans btw.
JavaFX for Java 7 is different from JavaFX on Java 8. My advice would be to go for Java 8. Then maybe NetBeans 8 too. JavaFX and swing/awt have different event threads, though under java 8 there seems to be a better integration.
JavaFX and java swing are two separate worlds. One might embed JavaFX in swing. Though if you are at the start of a basically new project, then you might go for pure JavaFX.
JavaFX uses "properties", wrapped values that can have change listeners on them / data binding. This separation from components makes dealing with the Model-View-Controller paradigm a bit nicer / different. JavaFX components themselves are a slightly more difficult, as swing provides a full API full of setters. It can be hard to make a column right-aligned for the first time. Another thing that makes JavaFX harder, is the use of callbacks with generic types, lambda expressions. Giving the correct signature not always is straight-forward.
So embedding JavaFX in swing might be a good approach if there is much swing experience or existing code: see
Embediing Swing in JavaFX (the other way around) and
How to Use JavaFX in Your Swing Application
If you mean, you have a NetBeans 7 Richt Client Application, then on the NetBeans.org there several small articles on JavaFX integration.

Is JavaFX supposed to supersede Swing?

I am used to Swing programming and have heard about JavaFX. Is it supposed to replace Swing as the preferred platform for writing desktop applications in Java?
To put it in another way, should I choose JavaFX for my new project?
Yes JavaFX is replacing Swing.
See also official documentation of Oracle:
http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html#6
Is JavaFX replacing Swing as the new client UI library for Java SE?
Yes. However, Swing will remain part of the Java SE specification for
the foreseeable future, and therefore included in the JRE. While we
recommend developers to leverage JavaFX APIs as much as possible when
building new applications, it is possible to extend a Swing
application with JavaFX, allowing for a smoother transition.
See also SO posts:
Swing vs JavaFx for desktop applications
https://stackoverflow.com/questions/1318645/javafx-or-swing (OLD)

Is it possible to embed a SWT Composite into a JavaFX scene?

I know that JavaFX 2.2 provides FXCanvas for embedding new JavaFX components into existing SWT Composites. Is it possible to do it the other way around?
My motivation for trying this, is that there are currently some components missing in JavaFX. For example a TreeTable. I want to implement my application in JavaFX, use SWT as a fallback for missing components, and migrate those to JavaFX as soon they are ready.
no - you can not embedd heavy weight (=SWT) into a lightweight container (=FX) - JavaFX will get a TreeTable in FX8

JavaFX Script and Java

Simple question: Can I mix in my desktop application Java and JavaFX Script code? If it is possible could you provide me with some link with examples?
Or could I pack my custom made javafx CustomNode-s in a jar and use them in my project side by side with standard SWING components?
This article gives an example of calling JavaFX from Java, using the Scripting API.
Yes, you can mix Java and JavaFX.
According to one of the FAQ entries:
In addition, developers can use any Java library in their JavaFX applications. This allows JavaFX applications to take advantage of the rich JavaFX UI libraries, as well as the amazing breadth of functionality offered by Java.
The official source of information, including tools downloads, FAQ, and tutorials is the JavaFX web site.
I suggest you to look at dotFX. It can be useful for you. It has a netbeans plugin,too.
Read first here for get more information.
You can use a JavaFX 2.0 with Swing
http://javafx.com/about-javafx/
If you install the JavaFX 2.0 runtime first, then you launch an example http://download.oracle.com/otndocs/products/javafx/samples/SwingInterop/index.html
Supposedly all you have to do is drag and drop the JavaFX application to your desktop in order to make it a desktop application. You can also use Java code in a JavaFX application. Not sure about the other way around.
Yes Javafx and java apis can be mixed and used in your application without any problems.

Categories