Essay sample library > Which one is better: JavaFX or Swing?

Which one is better: JavaFX or Swing?

2023-03-11 12:48:21

Under all the same conditions, JavaFX-API may be more consistent across components. However, this depends more on how the code is written than the library used to write the code.

It depends greatly on what you are building. Swing has more components (third party and embedded type), not all components are in the new JavaFX platform, so if you need something you need some reinvent of the wheel It may become. On the other hand, if you want to run conversion / animation / video content, FX is easier.

Another thing to keep in mind is (probably) a look and feel. If you need to have a default system look and feel, JavaFX (now) does not provide this functionality. I do not need it (I like the default FX look), but you can see that depending on the policy you need to restrict the system style.

Personally, I think that JavaFX is a UI library that will be released soon. It does not exist completely yet (although it is not only usable). Swing is now fully functional and supported It will be very large in the coming years (so foreign exchange may exceed it at some point.)

Oracle with JavaFX 2.X incorporates the official method of JavaFX into Swing, but unfortunately we can not embed Swing in JavaFX. In most cases this is enough. However, in future JavaFX 8, you can also use the Swing node to embed swing components in JavaFX applications. Simultaneous execution of two threads in the UI complicates the problem and may not make JavaFX integration as easy as expected unless you are using a simple applet. If you are working with a small application, you can do this with JavaFX.

Returning to JavaFX 1.3, you can embed Swing in JavaFX, but not vice versa. At least it can not be officially done. I implemented a Swing component that embeds JavaFX content (called JXScene) in Swing and makes it available for publication in the jfxtras project. This is the only way to embed JavaFX scenes in Swing applications. Oracle with JavaFX 2.X incorporates the official method of JavaFX into Swing, but unfortunately we can not embed Swing in JavaFX. In most cases this is enough. However, in future JavaFX 8, you can also use the Swing node to embed swing components in JavaFX applications.

In general, you can see that the JavaFX control hierarchy is more complete than Swing. Both have all the basic controls, such as buttons, check boxes, combo boxes. However, there are several interesting controls in JavaFX other than Swing, including collapsible TitledPane control and Accordion control that allows you to place multiple TitledPane controls in the stack. Indeed, these controls are superior to Swing because they can all apply skins through CSS. In contrast, JavaFX supports complex animations that can be applied to any node in the scene graph. You can use one of several built-in transition classes to perform common animations such as fade, rotation, motion path, and so on. Alternatively, you can easily set up custom animations using the KeyFrame and Timeline classes.