Build Java UI to run on all platforms - java

I am really confused over what to use. Options I see are awt, Swing and swt.
My question is which should be best for Desktop Java app on all platforms( Mac,Windows and Linux )with minimum platform dependent code ?

AWT is obsolete, though some of its classes and design form the underpinnings of the Swing API.
Here is my take on the differentiators between creating applications in Swing and SWT:
Swing
+ Forms part of the standard Java-SE platform, so fewer distribution headaches
+ You can create a consistent look and feel across platforms
+ Controls are lightweight, so creating your own is relatively easy
- If you need Swing applications to look like native applications, there may be a lot of work in it; Swing can be styled with a platform look'n'feel, but the results aren't always close enough for everyone's satisfaction
SWT
+ Easy to create simple applications which use native widgets
- Manual resource management
- You need to distribute platform-specific libraries
- You face the lowest-common-denominator problem - not all widgets are available on all platforms, so some will be custom to SWT anyway
Although I've put a lot more minuses against SWT, I wouldn't discount it. Which technology you pick will depend on your project requirements. Picking the library is only the beginning when it comes to UI development.
Swing is the easy, low-maintenance option and I'd agree with the other posters that this is probably the best fit for what you want.

Swing.
AWT is old and too low-level, SWT has native components, and doesn't ship with the JRE (it's a third-party library). Swing is high-level (-ish), and pure-java.

I would go with Swing as the best choice using what's packaged with Java. However, even Swing can make you jump through all the same hoops every time, so I would recommend looking into one of various frameworks that build on top of it and handle most of the boilerplate work of building an app.
There's a JSR for a Swing Application Framework which I have used when it was still in active development, but it's currently frozen. Their project page recommends a fork of that project, and another one called GUTS which uses Google Guice as its dependency injection. Netbeans also has Netbeans Platform.
I know the scope of these frameworks goes outside the realms of "UI", but they handle things like data-binding between your model and your UI which Swing does not do.

Related

Java desktop application frameworks vs. JavaFX

There are a lot of Java "application frameworks" such as those listed in http://pivot.apache.org/demos/ which pretty much all use Swing as the GUI toolkit, or in the case of Eclipse, SWT.
However I have not seen any obvious frameworks for JavaFX. Why is this?
If looking at the "Hollywood Principle", where the framework calls you, I would think JavaFX already does this, but then I'm confused because it would seem Swing and JavaFX do mostly the same role, which is as the GUI layer. But they both do event loops and callbacks/events/observer patterns, etc.
Does merely implementing an event loop and calling your event handler not qualify as an "application framework"?
If not, are there any frameworks based on JavaFX directly (rather than embedding JavaFX in a Swing control)? What would such a framework provide that JavaFX standalone does not?
Sorry for the "obviousness" of this question, but it's not obvious to me.
thanks.
There are plenty of them looks like your research has not been very thorough
http://efxclipse.org/ - in fact it leverages the same core stuff than the Eclipse 4 IDE / RCP 4 but replaces the SWT layer with JavaFX
http://www.jrebirth.org/
http://www.drombler.org/drombler-fx/
http://jacpfx.org/
As I'm the author of e(fx)clipse I'm biased but I know first hand that it is used on (big) commercial projects
In my opinion, Swing, JavaFX and also SWT are graphical toolkit, providing a set of basic widgets. There are not "Application" frameworks because their main goal is to display an User Interface. But you can use them to build an application without any other library by using basic features.
A good sample application can be found here: https://github.com/angelicalleite/museuid
It looks really nice with data picked from a mysql database, but if you read carefully the source code you can notice that all SQL queries are performed within the UI thread which will slow down the UI responsiveness.
This is one of the reason you should use an Application Framework.
Their goals vary and are numerous but they all are dedicated to ease your application development by keeping complex things (like multithreading, messaging) out of your application code.
Your choice shall be done according to your personal convictions about architecture and dependencies you want to use (or don't).
I'm the author of JRebirth (disclaimer), but I sometimes have a look on other frameworks, so you can make your choice by asking yourself some basic questions:
Do you want/need OSGI support ?
=> Yes efxclipse, DromblerFX, DEMUX
=> No JRebirth,JacpFX, DataFX, griffonFX, afterburner.fx
Do you want a minimalist framework?
=> Yes afterburner.fx
Do you want/need event messaging?
Do you want to share code?
Do you want modularization?
Do you require Java 7 support ?
How do you want to manage your application threads.
I certainly forget a lot of questions.
In fact you SHOULD use one of these Application Framework (building your own will be time-consuming), it will defintely speed up your developments and secure them, the remaining questions are :
What AF will fit your needs ?
What AF will be convenient to use for you and your team ?
Choosing an AF using patterns you don't like could be painful, in any case you can contribute to any available AF because they are all open sourced.
Hope it helps,
The simple answer to this is: JavaFX is much younger than Swing - at least as a standard JDK library. As a matter of fact, it only became a "real" standard part with Java 8. If you check the history, you see the following facts:
Before JavaFX 2 (released 2011), developers needed to learn a scripting language.
Also before JavaFX 2, the implementation aimed at being platform independent and therefore made no use of system-specific resources which can make a big difference in graphics and animation.
Read through it, and you'll find some more interesting details which can be summed up in that probably most developers have only been "seriously" noticing JavaFX within the last 5 years or so. Swing goes back much further (especially as being baked into the standard Java Runtime Environment), so naturally there are far more libraries aimed at Swing than at FX.

Rich client platforms versus JavaFX 2 versus Swing

Pretty soon now, we're gonna need to develop a GUI for creating configurations (more like scripts, to be honest) for our EAI solution at work. Think of a typical workflow editor. The visualization of the actual flows will most likely be a completely custom job, either in Swing, SWT or JavaFX 2. What I have trouble with choosing is whether to do everything else by ourselves or using a rich client platform.
In particular, I've noticed that JavaFX 2 is getting a lot of attention and seems to be really pushed by Oracle as the next big thing in the Java GUI landscape. The demonstrations look interesting and perhaps this newer API is more closely focused on productivity as opposed to the tons of boilerplate code that Swing tends to impose. Using a newer technology that gets a lot of support seems like a safe bet for future maintenance.
Using an RCP would have definite benefits for this project. Whether we go for Eclipse or NetBeans as the platform, having existing plugins/modules for viewing the underlying (XML) config, version control etc. would offer powerful functionality with minimal work. I also like the idea of having project types of our software next to Java projects in the same GUI. Even simple stuff like window management and customly arranging panels is much better handled by RCPs that what we could whip up.
So the question now is, what technology or combination thereof is viable? My options, as far as I can see, are thus:
Eclipse. I'm not too eager for using SWT, though, since I'm more familiar with Swing. NetBeans is also my primary IDE and I'm most familiar with it. It always felt more intuitive too.
NetBeans. This'd allow development of custom components in Swing. A lower learning curve for me.
NetBeans + JavaFX 2. This idea appeals to me... Use NetBeans for the RCP goodness and using JavaFX 2 for custom components. JavaFX 2 apparently integrates with Swing, but how well can this be done within NetBeans?
Swing or JavaFX 2. Do all the GUI work ourselves or use some existing framework(s) to get most of what an RCP offers. This seems like a lot of work but also offers superb control. I'm a bit loathe to try this in Swing. How well would JavaFX 2 suit itself to this?
Basically my only GUI experience is in Swing on small apps. This is the first time I'll be going for something that would warrant a RCP. But JavaFX 2 seems the way forward and I don't want to miss the boat on that one. If Swing might be on the way out, I'd prefer hopping onboard the newer technology.
If there are people who can share their experiences, have tried something like NetBeans + JavaFX 2 or are closer to the forefront of JavaFX and can recommend/discourage its use for this sort of thing I'd be most interested.
I realize it's a somewhat open question, but I can't really think of a more appropriate place. I'm not looking for a "what's the best RCP / is JavaFX better than Swing" debate. I'm looking for valid points for/against their use in this context.
My opinion in few lines,
JavaFX2 can be integrated into Swing and SWT applications into a panel/container.
Swing doesn't provide a structured architecture to deal with multi components applications, Eclipse RCP does but it's heavier and sometimes too complex (WindowWorkbench etc..) and hard to customize.
If you have a good UI Designer in your team (Developer or Graphic Designer) you should begin to work on an application Full JavaFX2 with a simple but powerful framework (like JRebirth or a custom one you can build on your own way).
JavaFX will be the Java UI Standard for years to come, It could'nt be a bad choice, thus its architecure is pretty good and powerful
Moreover javaFX2 could be used into a browser and/or deployed online with help of JNLP.
Don't bother you to learn complex undocumented framework (like EclipseRCP), create Yours !! and be free to make the application your client need :D
I worked 3 years on Swing Appz, 2 years on Eclipse RCP, and 2 years on Flex/Silverlight/JavafX apps
Here some points and (personal) opinions for helping you determining a proper solution for your current situation:
Eclipse vs. Netbeans
Personally, I dont't like big discussions about pros/cons of IDEs. Just use the one you feel most comfortable with. If you work in a team, make a voting. Considering Swing both IDEs are fine (IMHO Netbeans has the better GUI builder). Considering JavaFX 2.0 both IDEs are also fine but both share the absence of a GUI builder. I wouldn't recommend a mixture of IDEs.
JavaFX 2.0 vs. Swing vs. SWT vs. Eclipse RCP
Well, I don't - I even can't - want to tell you which of the above listed UI technologies is best since I don't know enough about your project's environment - experience, human resources, budget, timeline etc. Having a lean timeline and a team(?) of experienced Swing developers should lead the decision to Swing. Same for SWT and Eclipse RCP. Cutting edge developers might tend to try JavaFX. I agree, JavaFX gets a lot attention and you get great looking demonstrations, but keep in mind, that using JavaFX requires - additionally to the JRE - the JavaFX runtime on each client.
Hope this helps.
We switched to javaFx due to FXML usage,you can use MVC pattern ,you can add javascript and css init,but it seems slow when changing page

Essentials Java GUI building blocks? I.e. libraries to form a framework on top of Swing

Swing provides the basic building blocks for any GUI application but what about a higher level take on building GUI applications?
I'm not asking about the many arbitrary libraries that provide yet more wizzy variants on various visual components.
I'm talking about the missing pieces that everyone ends up building themselves whenever they create anything other than a trivial GUI application.
I.e. the framework that the application specific logic builds on.
E.g. handling data binding, application lifecycle issues or supporting common things like building forms.
If we were talking about persistence you could say that anyone can code up their own persistence layer using the javax.sql or java.io classes - however most people would rather use something like Hibernate.
So, just as someone asking about persistence libraries probably isn't looking for variants on ObjectOutputStream, I am not looking for variants on some JComponent subclass or other.
I think this is a fair Stackoverflow question as, unlike areas like persistence, a clear consensus on the answer is not easy to determine using Google.
Rather than a grab bag of random libraries perhaps people could answer in terms of what GUI issues are not immediately addressed by Swing and what libraries they feel best fill these gap?
I asked a similar question to this last week and it was closed - I've tried to phrase this such that this won't also be closed. If you feel inclined to close it perhaps you might consider making it community wiki instead?
Here are some essential libraries:
JGoodies - http://www.jgoodies.com/. This provides some nice layout tools (FormLayout) as well as common builders and databinding tools
SwingLabs - http://www.swinglabs.org/. This provides many common components you likely may need to use that are not part of standard swing.
Swing Application Framework - https://appframework.dev.java.net/ (already mentioned by jluzwick)
Groovy SwingBuilder - http://groovy.codehaus.org/Swing+Builder. This provides for easier building of GUIs by using a logical, hierarchical scripting-like language for building GUIs. It also has native support for some databinding.
Could you be referring to something like this?
https://appframework.dev.java.net/
This was integrated with Netbeans at one point and I don't think the development has continued, but this framework greatly helped me in creating a much more involved application with java.
EDIT:
It seems these projects are derivations of the former I mentioned that are actively in development:
http://kenai.com/projects/bsaf/pages/Home
http://kenai.com/projects/guts/pages/Home
JGoodies Bindings is great if you want to have a well-architected program.
NetBeans Platform (RCP) I really want to try. It's really the only viable Swing frameworks because ...
Swing Application Framework is very lacking and is not actively in development anymore.
MiGLayout is my favorite layout manager for cases where I used to use GridBagLayout (long time ago) and JGoodies form layout. Also, I dislike GroupLayout.
Have look at the NetBeans Platform (Swing based RCP)

Cross-platform desktop development

I need an advice for cross-platform engine/framework for desktop PC application development (Windows, MAC, Linux). I see 3 possibilities, Qt, Java and Adobe AIR.
It must be easy to install (run-time is a drawback, but C++ wrapper and/or installer can solve the issue I think).
It must be fast and have a rich GUI (not 3D game, but definitely some 2D graphics).
The development environment must be easy to establish and the UI development tool must have drag&drop functionality to define application layout.
Target application must have native look and feel. The professional paid support should be available.
All of these criteria are met by Qt, with the exception of "native look and feel". There is no such thing as a cross-platform framework with native feel, especially on OS X, where users are very demanding about the "feel" of applications. If you really want native look and feel, you are best served by writing a shared framework in C++ or C# and then providing native GUI on each platform (you can use MonoMac to provide a native Cocoa UI using C# instead of the native Objective-C, if that's your cup of tea).
That said, we've been very happy with Qt (and the Commercial support) for cross-platform development. Particularly the new OpenGL accelerated 2D Scene API makes animated UIs quite easy. QtCreator is a decent IDE with visual designer support.
Contrary to others, probably due to the fact that I worked on a real-time trading Swing application, I consider Java to be the best answer to your requirements (however, i consider this question as subjective, as previous answers already shows). Let me develop.
It must be easy to install (run-time is a drawback, but C++ wrapper and/or installer can solve the issue I think).
Using Java, you can rely upon Java Web Start, which is, as far as i know, the best solution for easy to use applications : you click a link on the browser, and the application is installed in start menu/desktop and started as soon as it is downloaded. Seems like Adobe AIR offers an equivalent feature, but to my mind Java Web Start integrates, due to the deepness of its ecosystem, far more powerfull distribution solutions (like, as an example, the easy ability to generate the .jnlp file on demand).
It must be fast and have a rich GUI (not 3D game, but definitely some 2D graphics).
Contrary to most popular belief, generating good graphics in Java is possible. Take as an example a look at excellent filthy rich clients companion site of the excellent book.
The development environment must be easy to establish and the UI development tool must have drag&drop functionality to define application layout.
Eclipse is a defacto industry standard for IDEs, and it integrate multiple DnD IDE builders. I would simply take as example the recently liberated Windows Builder Pro.
Target application must have native look and feel. The professional paid support should be available.
Well, Swing default look'n'feel is indeed a little different from system one. however, there are excellent third-party ones, listed here, as an example.
Finally, some examples :
the excellent Palantir Technologies blog list some outstanding Swing applications
Gephi is a rather complete and efficient high-volume graph viewer
My previous work (don't consider it as a masked ad, it's only a way to show some rather solid Swing).
I would not recommend Java for desktop development. I do not care what other say, Java is still slow compared to native languages like C++. I would go with Qt. The IDE has a GUI builder and can be integrated into Eclipse or Visual Studio.
Here's a helpful resource:
http://qt.nokia.com/products/
Have a look at Appcelerator Titanium: it basically wraps a web app in a browser. You can have anything you want in a GUI using wen tech, but it looks like an ap[p.
Strangely, nobody mentioned Real Studio (now Xojo) which does meet all your requirements:
It is easy to install and does not require a separate run-time
It compiles to native code so is reasonably fast
It has a good UI library that is native for each platform
The IDE is very nice with drag and drop UI designers
Target applications are fully native and use native controls
First of have to mention http://wxwidgets.org/ , one of the most popular X-platoform frameoworks. Depending on the complexity of your application and the requirements to the "nativeness", a cross-platform framework may work for you. The x-platform applications built with framework usually feel a bit "alien", especially on the Mac, but workable. A good example is http://taskcoach.org/.
If your users are tolerant to hearty download sizes, hefty memory requirements and a bit of non-native look-and-feel then plain Java, eclipse RCP or NetBeans platform can work for you. You may save quite a bit of development time going this route.
However I am not aware of cross-platform framework that satisfies all your requirements.
If you need to get to a production-level application, the strategy that I have seen worked best was to stay native but split the UI-dependent code into cross-platform (e.g. C++ business logic) and UI. This way, you will use native interface building tools (each platform has something good there). Depending on the complexity and "finish" requirements of your application you may actually save time going this route.
A great overview of the "Native X-Platform" process can be found in this answer by Chris Hanson.

What's the definitive Java Swing starter guide and reference?

Obviously the Java API reference, but what else is there that you all use?
I've been doing web development my entire career. Lately I've been messing around a lot with Groovy and I've decided to do a small application in Griffon just to experiment more with Groovy and also break some ground in desktop development. The only thing is I'm totally green when it comes to desktop apps.
So, world, where's a good place to start?
The Swing Tutorial is very good. Apart from that, the Swing API is obviously the reference, however it's also a treasure trove of fairly good source code! Add the API source to your IDE and you can jump directly to the implementation to all the Swing classes. This is a great way to explore the functionality, see how various Swing components work and learn a good Swing "style". Furthermore, it's great to be able to step through the API classes if things don't seem to work and you have no idea why! Adding the API source to the IDE has the additional benefit that you get all the JavaDocs along with it, although all modern IDEs can also pull them from the net -- you do not want to program desktop Java without the documentation available from within the IDE!
NetBeans and other IDEs do make the creation of IDEs very easy, but be aware that there is a lot more to Swing than just containers and layout managers. In fact, containers and layout managers are among the easier things, and I'd recommend learning to use them by hand, too. There is nothing at all wrong with using a GUI builder, but in some cases it's overkill, and then it's nicer to just quickly whip up a GUI from source. In other cases you need to be able to create a GUI dynamically and then GUI builders are no use at all! For creating very complex layouts from source, I recommend FormLayout, which has its own set of quirks, but which does scale (in terms of programming effort) to very big frames and layouts.
If you've only done Groovy so far, you'll be surprised how well documented Swing and the rest of the Java API is and how well everything is integrated. It might also take some getting used to a different style of programming, using the debugger more often and println-debugging less, etc. There might also be some "boiler-plate" code that will be very annoying. ;) Enjoy.
The Sun Java tutorials are pretty good. I cannot vouch specifically for the Swing one as it has been ages since I've done any Swing development and I have not read it myself.
Creating a GUI with JFC/Swing
When it comes to developing java desktop applications, I would highly recommend using the IDE environment Netbeans. Especially when it comes to the development of Swing based applications.
I recommend you to play around with netbeans. It will allow you to build complete GUIs using only your mouse. Once you get familiar with Swing components, start using the Java API. Thats how I started.
The O'Reilly Swing Book is a pretty good reference, it has a good overview of general Swing concepts and covers each of the major classes. I used it recently when I had to refresh my memory on Swing.

Categories

Resources