I am investigating creating a JavaFXPanel (see Redirecting) as a bean that is able to be added to a Swing app. This is mostly to add some functionality of the JavaFX such as providing a transformation (for example something like text perspective etc).
I will be requesting a project on ServoyForge to hold this “sandbox” in order to explore the rich functionality it may offer to supplement current UI controls.
Currently I have made a stand alone project to investigate the various JavaFx Controls (so far replicating the Slider, the TextField and Label).
The JavaFxPanel is the container that holds other controls. However most actions need to be performed on the JavaFx thread.
Is it possible to add the JavaFXPanel as a bean? My initial tests show partial success. My implementation is partially based on the ServoyForge SliderBean tutorial (see https://www.servoyforge.net/projects/sliderbean).
If any Servoyans have examined this or are going to and have decided that the current Servoy API is not suitable then I would appreciate a response indicating it is not worth while to pursue at this time.
Embedding JavaFX stuff in Swing is possible, best to check the tutorials/documentation on that from Oracle.
Challenge imho is that:
A- JavaFX isn’t available for all platforms just yet (For OSX they just released the SDK preview version)
B- JavaFX isn’t bundled with the JRE just yet (I think I recall reading they’ll start doing this from Java 8 onwards)
Therefor, if you embed JavaFX in your Smart Client solution, you have to make sure that JavaFX is installed on the client machine and you are currently limited to Windows (and maybe Linux already?)
Paul,
JavaFX 2.0 has been bundled with Java since 1.7. Version 2.2 beta 6 is now available for Win (32 and 64 bit) Mac and Linux. So not too far from being on all these platforms. There is also a scene (UI) builder now available as well.
My main issue now is whether or not I can get the JavaFxPanel (the control that is able to be put into a Swing app) into a bean form so as to be able to use in a regular Servoy UI.
Since the controls of JavaFx have to be executed on a JavaFX thread I need to be able to synchronize correctly.
I would like to know the Servoy API better so that I can have this second thread running.
I have already built the bean using the examples from Servoy Forge on bean building.
However I would like to know the sequence of the calls to initialize and constructors and any other method calls for say location, size setting colours etc. I do know about the IServoyAwareBean interface and the IComponent interface and am compliant with those. It would be nice if there was any other documentation that helped. Some of the API java doc is a bit light in terms of what the design is.
Any others interested in collaboration are welcome.
This is primarily a self-learning exercise. If it is possible to provide some interesting GUI features over and above that presently supplied then that would be nice too.
Once I get the basics working then I can supply some examples.
JavaFX 2.1 is bundled only with Java 7 SDK, not Java 7 JRE, which means that it won’t be installed on the majority of client machines, which normally only have the JRE installed.
As for platform support: yes, they seem to have make some good progress, but for some platforms it’s still just a developer preview that is available.
As for your bean questions: I guess it’s doable, as beans are just plain Swing elements, but this is not my area of expertise.
Paul,
thanks.
The SDK is what I would be using for some time anyway to learn.
I am not expecting this bean to be production quality until as you say it is available in the jre.
Check out this Scene Builder video, I like what I see:
B.t.w. the JavaFX 2.x runtime libraries will be included in the JRE as of Java Se 7u6 which will be released this summer. Scene Builder will be released as a separate product and is still in the developer preview fase but is expected to be released together with JavaFX 2.2 this summer. Concurrent OS support on Mac OS and Linux however is not expected until 2013/2014.
Looks like this is the future in UI design for JAVA based development which targets not only the web like most RIA´s (rich internet application platforms) but also provides the extra power and control that you want for native apps.
Also check out this three part real world conversion of a swing based JPad (NotePad like) application to it’s JavaFX2 counterpart:
Update
Yes I have been quietly working and learning the SceneBuilder and so on.
The hardest part as always is trying to understand the beans interface in Servoy and debug it so as to be able to use the JavaFx as just another [Swing] component. My success to date has been to create a bean and it gets displayed on the Servoy 6.0.x “occasionally”. By that I mean that sometimes the bean is displayed properly and at other times it seems to be hidden and invisible.
My next foray will be to use Servoy 6.1 api in the debugger and try out my bean. So no luck yet in putting up on ServoyForge until I get the hang of the myriad calls to the create and instance of a bean form the developer!
There might have to be a change in the Servoy API in order to make the JavaFx thread run as well.
I took a slightly different approach and reverse engineered the dialog plugin which kind of does the same integration of Swing with Servoy as what we want to achieve with JavaFX2. Currently I am able to instantiate a FXML Scene Builder form from Servoy without the integration. I am currently messing arround with code similar to the function below because I believe that is where the thread integration magic happens.
private void createAndShowDialog(String title, JOptionPane pane)
{
// get clientplugin access
IClientPluginAccess access = plugin.getClientPluginAccess();
// get a reference to the runtime window
IRuntimeWindow runtimeWindow = access.getCurrentRuntimeWindow();
Window currentWindow = null;
if (runtimeWindow instanceof ISmartRuntimeWindow) currentWindow = ((ISmartRuntimeWindow)runtimeWindow).getWindow();
pane.setComponentOrientation(((currentWindow == null) ? JOptionPane.getRootFrame() : currentWindow).getComponentOrientation());
[b]JDialog dialog = pane.createDialog(currentWindow, title);[/b]
modalizeDialog(dialog);
pane.selectInitialValue();
dialog.setVisible(true);
dialog.dispose();
}
JavaFX in its current iteration would have been very cool…four years ago. I believe Sun dropped the ball in not pushing its development.
Today, the reality is that runtime based technologies are done for client-side development. Even with a prom dress on they aren’t getting into the party. Adobe Flex and Microsoft Silverlight are way ahead of JavaFX’s capabilities and look at what trajectory they are taking…
JavaFX (scripting language) is very dead indeed and has been discontinued by Oracle earlier this year. But JavaFX2 (new Java based version of JavaFX) is very promissing imho.
The principal reason for me investigate JavaFx now is purely intellectual.
I have no interest in whether or not the technology lasts or not. It is interesting to me at this time and that is important to me.
It would be more interesting (obviously to me only it seems ) if I can get a decent “framework” (to use an over-used expression) created to work within the Servoy UI API so that I could experiment.
So while this might be academic to some, to me it is interesting to see what could be done and what might be done differently using JavaFx. For instance I am looking into the webkit.
Another update:
I am getting stuck on the display of the bean. Sometimes it is displayed and other times it is not.
When I use the debugger, stop on a break point, and step through it seems to be displayed (more often than not). See attached screen shots in which I have a Slider in horizontal and vertical mode).
When I run without breakpoints then it is never displayed.
So now I suspect there must be some issue with threading on the EDT and the FxThread. Perhaps the FXThread is not being run at an appropriate time.
What is the next best step to investigate?
I am using the Servoy 6.0.x release and JDK 1.7.0_u5 (which has JavaFx 2.1).
Is there some document or other assistance that describes the bean side of Servoy? I am looking to see if there is an appropriate place to introduce a place to call the JavaFx thread to perform Platform.RunLater (so that I can get it rendered and therefore show on the Servoy developer).
Right now there appears to be calls to create the bean two or three times when invoking the Servoy developer. So it is quite confusing as to which one is the “real” one and not just reflection to find methods etc.
This will not solve your bean problem but it does show you how to merge the Swing thread with the JavaFX thread. I got this to work from Servoy. Integrating standalone stuff like a JavaFX login form is doable but sooner or later you will want to bind foundsets and dataproviders to the JavaFX components. Hopefully Servoy will adopt this technology in a future release which should make that a lot easier… In the meanwhile really cool graphic stuff is already possible. I am convinced JavaFx2 will succeed Swing at some point, especially when JavaFx is integrated with JRE (expected this summer in Java SE 7u6).
I agree that it must be a threading issue.
And I can only imagine them being multiplied by two when running in developer on Mac OS X as well, with SWT/AWT event pump already competing for process time on the main thread…
As to document or assistance, I suppose it’s rather a DYI: basically launching Servoy from the sources, and adding various breakpoints and logs to understand what’s going on.
And yes a bean is created more than once in Developer. Once for JS introspection, once for the form editor, once in the debug client. And even another time in print preview.
Whether these instances work well together is another story…
Keep in mind that in Developer in the Servoy editor,you are really in a SWT environment. So AWT/Swing is already running from the SWT_AWT bridge, which has it’s own set of issues (and has many threading issues on Mac OS X)… But once in Smart client (debug client) does your bean display or not? You’re not saying.
Is your bean an instance of JPanel and your FX scene embedded in it? I suppose that’s how I would have done it, but it’s hard to tell since we don’t see your sources.
I would for example check when a bean is added to a parent (and removed), so override addNotify() and removeNotify() and put some logging here, check the size of it, see if the bounds are correctly computed.
Also override setBounds() and/or setSize() because a lot of calls happens here and sometimes at wrong time…
In the end, what I would advice is create a new project on ServoyForge, commit some code to it so that others can have a look and a try and maybe help you debug this thing (you can add members to a project without making it totally public).
Remember that ServoyForge is a collaborative tool and was created for that very purpose of allowing remote developers like us to build something together, whether your code is currently working or not is not important as long as you’re supplying enough background and comments. Seeing how you’ve done it might give us some clues on how to help.
As to JavaFX succeeding Swing at some point, I’m less optimistic, I’m afraid it will not happen for a long time in Servoy.
First because the currently supported JRE is still Java 5.
And also because all the current layout code and core components in Servoy are made with Swing.
So integrating JavaFX components, apart from external beans for marginal usage is unlikely to happen soon…