What new changes came with Swing in Java 8? - java

Are there any changes than came with Swing and AWT in Java 8? In release notes for Java 8 I it's not mentioned.

I don't think so...
Swing has really old API, oracle left it behind in favor of JavaFX - which does have (and still developed) methods that use the new APIs.
Edit: just remembered, the only new 'feature' that I know of that was added to swing is the JFXPanel which is a way of integrating JavaFX components into your app swing-fx-interoperability

Related

Can JavaFX be included on a Java SE project?

I'm trying to create an Inventory project and have graphs on it. I'd like the graph to be created thru JavaFX and call it on a Java main class. Is it possible to add a JavaFX class to a Java project?
I'm using netbeans btw.
JavaFX for Java 7 is different from JavaFX on Java 8. My advice would be to go for Java 8. Then maybe NetBeans 8 too. JavaFX and swing/awt have different event threads, though under java 8 there seems to be a better integration.
JavaFX and java swing are two separate worlds. One might embed JavaFX in swing. Though if you are at the start of a basically new project, then you might go for pure JavaFX.
JavaFX uses "properties", wrapped values that can have change listeners on them / data binding. This separation from components makes dealing with the Model-View-Controller paradigm a bit nicer / different. JavaFX components themselves are a slightly more difficult, as swing provides a full API full of setters. It can be hard to make a column right-aligned for the first time. Another thing that makes JavaFX harder, is the use of callbacks with generic types, lambda expressions. Giving the correct signature not always is straight-forward.
So embedding JavaFX in swing might be a good approach if there is much swing experience or existing code: see
Embediing Swing in JavaFX (the other way around) and
How to Use JavaFX in Your Swing Application
If you mean, you have a NetBeans 7 Richt Client Application, then on the NetBeans.org there several small articles on JavaFX integration.

Is JavaFX supposed to supersede Swing?

I am used to Swing programming and have heard about JavaFX. Is it supposed to replace Swing as the preferred platform for writing desktop applications in Java?
To put it in another way, should I choose JavaFX for my new project?
Yes JavaFX is replacing Swing.
See also official documentation of Oracle:
http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html#6
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.
See also SO posts:
Swing vs JavaFx for desktop applications
https://stackoverflow.com/questions/1318645/javafx-or-swing (OLD)

Java - Building GUI for application

I've written a lot of Java applications over the years, but the vast majority of them have been simple command line programs with only a few hundred lines and (at most) several classes.
My question is this:
How do I now design/code an interface to this application?? Where do I start? I mean are there any tutorials/resources which describe the steps involved?
I know Swing exists, but where do you start, and is it the only option?
Any help/assistance appreciated...
The rich client GUI toolkits for Java are basically:
AWT Sun's Abstract Window Toolkit was the original component kit for making GUIs, a toolkit based around using native components. AWT still contains the core of very important parts of J2SE GUIs such as Graphics/Color/Java 2D, Image & BufferedImage, printing, D'n'D..
Swing The current, main-stream desktop app. component toolkit. Swing generates the components internally, and allows setting a Pluggable Look and Feel to the GUI. Swing offers components & functionality not available in AWT such as JTable, JTree, support for formatted documents (e.g. RTF & simple HTML) in Swing components.. For more information see things that Swing provides beyond AWT.
Java FX 2 Intended as an (eventual) replacement to Swing, AFAIU.
SWT is another choice, not written by Oracle, uses natives. I would not recommend it for someone learning rich client programming, since it is a lot easier to get answers in relation to Swing.
You have to learn core GUI API java.awt and its sub-packages along with (extended API) javax.swing and its sub-packages. You may start - The Java Tutorial.
No, Swing is not the only option but it is where you should start. Swing is the "new and improved" version of some of the GUI objects in java.awt. Most of the Swing objects build off of their AWT counter parts our are completely new. Both Swing and AWT are a part of the core Java API so it would be best to start with the tutorial that AVD linked you to (The Java Tutorial)

How to wrap a swing component in a javaFX 2.0 application

The ability to wrap a swing component in a javaFX application seems to have vanished from javaFX 2:
javafx.ext.swing.SwingComponent
is not there any more in javaFX 2 beta API.
Is there still a way to do this in the new API?
SwingNode class is used to embed a Swing content into a JavaFX application.
Here is the link.
There is 3rd-party support library, see http://rkennke.wordpress.com/2011/11/16/swing-in-javafx-demo/
According to this issue on the FX 2.0 JIRA they aren't planning to support it in the initial release of FX 2.0. There's also no promise that they will do it down the road.
http://javafx-jira.kenai.com/browse/RT-12100
It seems that since javafx 2.0+, we can't embed Swing component into JavaFX (vice versa is possible, using JFXPanel class), detail in this link:
https://forums.oracle.com/forums/thread.jspa?threadID=2364553&tstart=0
I accidentally found this link when trying to embed Swing Calendar view component into JavaFX 2.0 application (which I suppose it's possible at the beginning).

If Swing is deprecated, what is the alternative?

I heard that apparently Swing is being developed no longer. I like Swing and use it all the time.
What should I now be using instead?
I never heard such thing and still developing swing apps. Don't give wings to rumors.
But as an alternative you can use JavaFx or swt or buoy.
You probably read something about the 'Swing Application Framework', which while built using Swing, is not 'Swing'.
From Swing Application Framework - Status and Roadmap.
Development on an open source Reference Implementation called appframework was begun in 2006.[1] It was originally expected that this implementation would be the means for integrating JSR 296 into the upcoming Java SE 7 (Dolphin) version of the Java programming language, and the project was scheduled to be included in milestone 5 of the JDK7 development. However, in August 2009, it was announced that the project would not be included due to an inability to reconcile design flaws and achieve consensus among the JSR 296 team before the milestone 5 deadline.[2]
The original Swing Application Framework implementation has been put on hold indefinitely.[3] The last public release of the appframework project is version 1.03.[1]
Older question, but worth a reference:
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.
http://www.oracle.com/technetwork/java/javafx/overview/faq-1446554.html#6
Jan 2019 Latest
For reference, AWT & Swing have been moved to java.desktop since Java SE 9. You can watch for future changes here. JavaFX (added to JDK since 8) was removed from the official JDK in Java 11. So its hard to say what is "official" anymore. However JavaFX's development has increased since the decoupling, with its new home here.
The Standard Widget Toolkit.
There is nothing wrong with swing. Personally i don't like SWT. You have to read input-values from widgets and store them in normal variables before a dialog is disposed.

Categories