Starting on JavaFX - JavaFX version and “developme

2019-02-17 06:28发布

I am planning on starting the development of a desktop app, but until now, for me, desktop = swing. I did a little research about it and found myself under some questions:

  1. I found that there are a lot of JavaFX versions:

    • There is JavaFX 1.0 that people say is old and outdated;
    • There is JavaFX 2.X that is very good;
    • And now JavaFX 8 (is this correct?);

    But even with the most recent NetBeans IDE version (8.0) with JDK 8 (1.8.0), when I create a JavaFX application, it starts using JavaFX 2.2 – Is JavaFX 8 really a new JavaFX version or people say it just because they use JavaFX 2.X with JDK 8?

  2. Another question about versions, will applications developed in a version X of JavaFX be compatible with higher versions? Just like a swing application, where if you developed an application in Java 5, it would work even on Java 8.

  3. About development patterns, more specifically about layout creation, I noticed there are two ways for creating layouts: By just coding it in Java, and by creating XML files (FXML) with a Java Class as a controller (More MVC approach) just like a JSF application. Which one should I choose? What are the pros and cons of each one?

1条回答
Fickle 薄情
2楼-- · 2019-02-17 07:10

Welcome to the world of JavaFX

I am not sure why you are facing such an issue of JavaFX 2.2 with JDK 1.8 because JDK 8 has JavaFX 8 in it and it must be used by default.

Just to give a quick introduction on JavaFX and how it is different from Swing. Please follow the following points:

  1. Instead of following the legacy of building the view/UI in Java code and messing your functional codes with views, you get the opportunity of separating the view with the functionality using the FXML introduced in JavaFX 2.0+
  2. JavaFX has powerful CSS integration which allows you to decorate the view, which was absent in Swing.
  3. The development is quicker, as you have SceneBuilder to back you.

For more differences on Swing and JavaFX please follow (though the answers are old and many things have changed. JavaFX has become bigger and better!)

https://stackoverflow.com/questions/1318645/JavaFX-or-swing

JavaFX 2 vs Swing for a pure Windows desktop app

Difference between JavaFX 1+, 2+ and 8+

  1. JavaFX 1+ was basically a scripting language called as JavaFX script, which was very different from the Java language.
  2. JavaFX 2.0 changed the face of JavaFX. All of JavaFX API was now available as pure Java API. FXML was also introduced during this phase in JavaFX!
  3. JavaFX 8.0 leads to a new face of JavaFX where JavaFX is accepted as an integral part of Java 8.

Compatibility - All JavaFX application is forward compliance, i.e. JavaFX 2.0+ is compatible with Java 7, 8 and above. Though applications made using JavaFX 8 is not compatible with Java 7.

JavaFX 1.3 support has been killed from Java 1.7.

Development Patterns

  1. JavaFX gives a chance to build your application using your choice – i.e. use the legacy method of building the view using pure Java or use FXML.
  2. JavaFX strictly follows MVC pattern, separating your view and its events. The views are created using FXML and the controllers are Java files.

From Oracle docs

From a Model View Controller (MVC) perspective, the FXML file that contains the description of the user interface is the view. The controller is a Java class, optionally implementing the Initializable class, which is declared as the controller for the FXML file. The model consists of domain objects, defined on the Java side, that you connect to the view through the controller.

Some more information and pro's for FXML, please follow:

Which is better way of programming in javafx?

查看更多
登录 后发表回答