Similar to a Swing based guitool, the osgisnippets project contains a JavaFX 2 based guitool. It is located in the project guitool in the package example.guitool.fx . The package is essentially a copy of example.guitool with adjustments to make it work with JavaFX.
Embedding OSGi into JavaFX
The class OSGiFwLoader takes care of the main work of starting and stopping the OSGi framework and managing bundles. In Embedding OSGi the main features of the OSGiFwLoader class are described. There is one major difference between the version there and the JavaFX related version.
The goal is to load bundles which use JavaFX components. To do that, the bundle imports javafx.* packages. These packages must be made available and this is done in OSGiFwLoader.prepareConfigMap():
The bold lines let these JavaFX packages be exported by the system bundle and are thus available to the bundles which use JavaFX components. (If further packages are required, they need to be added to the list of packages.)
The JavaFX GUI Tool
The JavaFX gui tool shall be able to start bundles which display Swing components. As described in JavaFX and Swing (on a Mac) some extra steps are necessary to allow Swing components to be used in JavaFX. Instead of the typical Application.launch() call, Swing is started first and JavaFX is embedded there:
Doing these things on a Mac was leading to more issues than under Windows. If it is good enough under the circumstances, the following start method may be used too:
Things are changing a lot currently so this jumping through hoops may not be necessary in the future (JavaFX 1.x reaches EOL, JavaFX 2.x in JDK7 is out for a while, JavaFX 8 is available as early access and parts of JavaFX already went Open Source).
- JavaFX: http://javafx.com/
- OpenJFX / OpenJDK: http://openjdk.java.net/projects/openjfx/
- Article about embedding Swing in JavaFX: JavaFX and Swing (on a Mac)
- Article about osgisnippets' OSGiFwLoader class: Embedding OSGi
- Apache Felix: http://felix.apache.org/
Article about embedding at Apache Felix site:
Apache Felix Framework Launching and Embedding
Source code of OSGiFwLoader is at the project site: