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)
Related
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.
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)
I want to develop a simple desktop application that connects to the Java DB , using Java Swing for the interface design.
I am new to Swing so I tried some tutorials on the net and came across
the Netbeans platform Swing components.
What is
the difference between the Java Swing architecture and the Netbeans Swing components?
Which one will be appropriate for developing interfaces
for desktop applications in Java?
From The NetBeans Platform:
The NetBeans Platform is a generic framework for Swing applications. It provides the "plumbing" that, before, every developer had to write themselves—saving state, connecting actions to menu items, toolbar items and keyboard shortcuts; window management, and so on.
It is an API built with Swing, that is supposed to provide some extra 'built-in' functionality. Since you need to know Swing to be able to use it. I suggest you concentrate on Swing for now.
Actually, it will be better to move on Intellij Idea from Jet Brains. It’s much more better than NetBeans IDE. Of course, it’s only my opinion.
I'm too far from Java technologies.
Just for curiosity what is the name of the technology/API/class which let us develop desktop applications with Java (like windows forms)?
I heard a toolkit named Swing. Is that the official GUI toolkit and is there any alternatives of Swing?
Is there a technology in Java corresponding to WPF of C#?
Java Swing is the most commonly used GUI toolkit for Java. There are alternatives (JavaFX, AWT, SWT), but Swing is a very good starting point if you start devolping desktop applications with Java. The only thing I would consider is looking at alternative LayoutManagers like MigLayout. But you can easily begin with the standard ones. There is a great visual guide to start off with Java Swing and the various LayoutManagers.
There is AWT, Swing, SWT, JavaFX, Android GUI.
The most common is Swing and while its not the prettiest, I would start with that unless you have specific requirements.
Java FX 2.x demo http://www.oracle.com/technetwork/java/javafx/samples/index.html
Java has the following options for GUI development:
(1) AWT
This is the old GUI development library
(2) Swing
This is the new GUI development library
(3) JavaFX
This is the latest GUI technology of Java,
it comes with FXML for fast UI development.
FXML is not compatible with XAML of .NET, but it can be considered equivalent.
Yes, Swing is the official GUI toolkit of the Java Runtime Environment.
in Java you can use many differen GUI technologies.
Swing is one of the technologies you can use. It is lightweight and it is the offical toolkit for Java.
Furthermore you can take a look at SWT, AWT or JMonkey for 3D stuff.
What do you mean with similar with WPF? The MVVM Pattern?
Something similar to Silverlight but better is the GWT Toolkit.
If I want to code an desktop application in Windows with Java, should I buy a book about Swing and just skip reading books/tutorials about AWT?
Or do I have to learn AWT before using Swing?
Just go straight to Swing.
Ignore awt.
There is no benefit getting your head around awt, as Swing is essentially a replacement for it.
There's really no point in learning AWT first. Swing replaces a lot of AWT's concepts and components, but integrates many others unchanged (such as layout managers). If you learn Swing, you'll learn those parts of AWT that still matter (and how they are used in Swing) pretty much automatically.
Sun's Swing tutorial is a pretty good starting point.
If you're doing this for yourself (and not part of work), might I suggest trying out the Qt or Gtk Java ports?
I don't know much about the Gtk one, but the Qt one is called Qt Jambi, and it's development is currently community driven, LGPL licensed. I've used both Swing (in Java) and Qt (for C++ apps), but if I ever had to develop java desktop applications again, I'd definitely give Qt Jambi a look before I decided what to pursue.
As for the Swing vs AWT - Swing straight away I would say.
Well, Swing is richer in terms of out-of-the-box components than AWT. I have used both, and i prefer Swing over AWT. Also, you do not need to learn AWT to learn Swing basics.Sun's Swing tutorial
is a good source to start learning Swing framework.
As other answers have already mentioned there is no need to learn AWT and you can
get your GUI coding with Swing alone.
As you develop your GUI code invariably you will bump across some
AWT class (for example java.awt.event.ActionEvent) and you can comfortably use it by reading
its API documentation. However your application need may make you to use a layout manager
like GridBagLayout(java.awt.GridBagLayout), in which case you may have to study the layout manager
documentation bit more in detail. I found this book on AWT Java AWT Reference, which is available online freely, to be quite useful when I needed to dig a bit more in detail about layout managers.
There is no need to learn AWT before learning Swing.
Net Beans is a good IDE to learn Swing.