Roles of JavaFx 2.0, Swing, and Java 2D in Java 7 Ecosystem - swing

I am a bit confused as to the new standards. To the best of my understanding Swing -- the former standard interface library -- is based on it's predecesor, AWT, and the Java 2D graphics libraries.
Now that JavaFx 2.0 has replaced Swing my question is where does Java 2D fit in? Is it possible to use Java 2D methods to generate graphics on JavaFX interface elements?
Thank you

From the Oracle client tech lead's 10000 foot view of JavaFX.
At various times people have written articles or blog posts or forum posts asking the question, what is JavaFX? ... Is it a replacement for Swing? (The answer would be an emphatic Yes).
Mostly, use of Java2D is unnecessary with JavaFX as JavaFX has strong immediate and retained mode 2D apis.
If really needed, you can use Java2D methods to render to a buffer backing a JavaFX WritableImage or an awt image which you can later convert to a JavaFX image.
To an extent, you can still use Swing together with JavaFX if you want or need to. For example people have embedded a JavaFX webview in the Swing based NetBeans platform.

Related

JavaFX GUI, easiest way for complex 3D Graphics

I am creating a software for calculating gearbox parts using Swing and OpenGL (with JOGL).
With this software the calculated parts are shown in 3D. The following picture shows an example part:
At first the geometry is specified/calculated (tip/root Diameter, width, number of teeth...) and out of this data the 3D-part is created. This example part is made with JOGL-Code because it's easy to use for me and can be integrated in a Swing-GUI.
Now a played around a bit with JavaFX Application GUI's and decided to continue making my software in JavaFX because it offers everything i need, looks much better and so on. The problem is I can't use my JOGL-OpenGL graphics.
So here are the possibilities for me:
Search for a way to integrate OpenGL-graphics in a JavaFX-Application - but I googled a bit and this seems to be quite difficult and the possible solutions seem to be very slow.
Use JavaFX integrated 3D-graphics (TriangleMesh) - but this is difficult to understand and I can't find good examples to learn it.
Any other solution?
Can you please help me finding a good solution? What would you do? My favorite would be to continue using OpenGL, but is there any good solution for this yet?
If you are looking for some JavaFX 3D resources that may help you decide whether its already mature or not, these are available, among others:
3DViewer here from the OpenFJX project.
InteractiveMesh importers and browser.
F(X)yz, a new JavaFX 3D library that provides additional primitives, composite objects, controls and data visualizations that the base JavaFX 8 3D packages do not have.
Multimodel3DFX, repository contains the code for the example shown on the article "Building Castles in the Sky. Using JavaFX 3D to model historical treasures" published in Oracle Java Magazine, issue from November/Dicember 2014.
Using a PolyLine3D from F(X)yz and the Multimodel3DFX plaftorm I was able to extrude a 2D polyline of a spur gear, so you can see how it's rendered in a JavaFX 3D subscene:
These are also mathematical 3D models generated using the F(X)yz library, all of them based on TriangleMesh.
As you can see, JavaFX 3D API, with its pros and cons, can be easily extended to achieve complex tasks.

building the interface of an eclipse plugin with JavaFX or HTML5?

I am looking for an alternative to swt for building the interface of an Eclipse plugin I want to develop.
Is it possible to build the interface of the plugin with JavaFX or HTML5 instead of swt ?.
I am targeting Eclipse Juno 4.2 or later.
Eclipse 4 defines an application model, i.e. a model of all the parts forming the application UI. The application model is decoupled from its presentation.
This means that different UI toolkits (SWT,XWT,JavaFX,etc.), can be used to implement the model. Theoretically you can build a UI using any presentation technology you want.
That said, Eclipse 4.2 (the IDE) still relies on good ol' SWT for it's UI. Which means, your plug-in will require some additional dependencies to be able to use a different toolkit.
e(fx)clipse (already mentioned by jewelsea), provides the necessary Eclipse tooling to build your plug-in. Among other things it plugs a JavaFX ViewPart plug-in template, which creates an example plug-in and adds the necessary bundle dependencies for you.
Imho, this would be your best bet.
There are lots of things going on, Eclipse versioning can be a bit confusing nowadays (at least for me), you can take a look at E4 but it is not widely used. It has the ability of desining UI with Eclipse RCP/CSS.
An other posibility is XWT. I've seen some business ready application using XWT so it seems to be mature enough. Even WindowBuilder can be used to build UI with XWT. Which is actually declarative UI constructing with XML. If you want to have only the OSGi "goodies" you can take a look at Apache Felix or Eclipse Virgo (Spring-powered). They are application servers based on OSGi so you can build module based enterprise applications.
Last but not least if you are OK with SWT/JFace but want to have web application, take a look at RAP. I have seen a full RCP application converted to RAP running in a regular browser.

JavaFX 2 vs Swing for a pure Windows desktop app

I need to write a desktop app and its been a while since I started used Swing so will have a learning curve with either technology.
Are there any advantages in doing my app using JavaFX 2?
4 Years back I was having the same question and came to the conclusion that I would be best of using Swing since a lot of third party libraries were still written for Swing in those days. Also 1.0 releases from Sun were usually a bit rough around the edges (I burned myself on JSF 1.0 and JPA 1.0 :-).
Today a lot of libraries have JavaFX counterparts or are available as JavaFX library. That said there are also a lot of libraries wich are still Swing exclusive. Also I've done some small things with JavaFX 2.0 and it seems really complete. I haven't bumped into any showstoppers.
You need to check how many external UI libraries you are going to use besides Swing / JavaFX (and which one). If the answer is not many or a lot have a Java FX alternative (or are simple to todo yourself) I would definitly go for JavaFX. Also you can still use Swing components in JavaFX.
As stated JavaFX is going to deprecate Swing in the future and Oracle seems committed on JavaFX (it also going to be opensourced). So I would highly recommend JavaFX.
Status update 13 april 2014:
JavaFX has been opensource for some time now: https://wiki.openjdk.java.net/display/OpenJFX/Main
The community is committed to JavaFX; JavaFX only libraries with no swing counterparts are starting to emerge.
Oracle has proven to be committed on JavaFX.
In case you weren't convinced 2 years back: JavaFX now definitely looks like the way to go. Though Swing will probably around for a long time it is currently in maintenance mode. It will take a lot of effort to port large applications (like IntellIJ or Netbeans) completely to JavaFX. And for those large applications such a large scale port is probably not worthwhile at the moment.
Status update 15 september 2021:
The JavaFX community is still going strong. OpenJFX is still there and has a flashier home.
Companies like Gluon (I'm not affiliated with them) offer commercial support LTS releases for OpenJFX.
There is GraalVM support for JavaFX allowing you to make JavaFX applications and distribute them as native binaries (ie. no JVM needed).
There are excellent opensource JavaFX component libraries available like TilesFX.
Both are good options:
If you want a rich, graphically enhanced application, the features of JavaFX 2.0 may be very appealing. It is designed to give you a lot of creative control over your user experience and visuals. Just be sure that it is supported on your target platforms....
If you want a standard desktop application that runs on as many platforms as possible, then Swing is probably a safer choice (since Swing is guaranteed to be available as part of all modern Java distributions). It also has the advantage of more mature 3rd party libraries.
Neither is likely to replace the other: they have slightly different target uses and will probably co-exist for many years to come.

Will Java 8 be able to have another release of Swing?

Taking into consideration Project Jigsaw for Java 8 (to modularize the JDK), will a "new" Swing Framework be able to be taken into consideration?
Consideration means:
someone actually rewriting it
including it into a JDK release
I'm thinking, since modules can be included into the JDK, a new framework for Swing can be created and delivered for use to new applications developers, while, for the legacy applications, the current Swing framework would be included.
Would rewriting a new Swing and including it into the new JDK be an option for Java 8? (What are your opinions and considerations to take into account for this task ?)
It was not included in Java 8, and is highly unlikely that it will even be considered for Java 9.
According this JavaFX page, JavaFX is the replacement for Swing:
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.
In addition, Project Jigsaw is now targeted for Java 9.

OpenGL style stack library for as3

I am currently working on a 3D engine in AS3, I have designed it for the new upcoming Molehill API but I also want to render to the current AS3 graphics API. I thought that I would write a stack based implementation to render to the target DisplayObject. I then realised that I could essentially create an OpenGL API style interface to abstract my 3D engine from the actual rasterizing processes. (Just like any 3D engine built on OpenGL) This would also then allow other 3D engines to make use of the code as with any other imported library. Obviously there would be functionality handling the viewport, matrix stack etc, but a simple example my be:
AS3GL.begin( AS3GL.GL_TRIANGLES );
AS3GL.color3f(1,0,0);
AS3GL.vertex2f(0,0);
AS3GL.color3f(0,1,0);
AS3GL.vertex2f(.5,0);
AS3GL.color3f(0,0,1);
AS3GL.vertex2f(.5,.5);
AS3GL.end();
I wondered if anything like this already exists for AS3 that I could use, or if anyone has any detailed information about the inner state systems and/or stack implementations of OpenGL.
Adobe Mole here. What you want to do is very possible. You should start with reading old OpenGL specs. However please consider what you really want to do and why. As an educational exercise it is great to map tech from the 70s to a modern API. If you want to do a useful library or learn modern 3d, this is a dead end. One great thing about the Molehill API is that it does the right balance between a scripting language and GPUs: Use script to batch big chunks of triangle drawing. Doing multiple calls for every single vertex defeats that model.
I have decided to start this as a project myself, if anyone wishes to contribute please contact me. I have registered the site AS3GL.com and setup a google code repo ready for this. If anyone is able to send info about the stacks and inner workings of OpenGL, I would appreciate any info.
[EDIT]
This library became discontinued, but here is the GitHub repo for reference 'dev branch' https://github.com/Zest3D/as3gl/tree/dev