How do "professionals" make a GUI in java? - java

Thanks for your answers to my previous question about GUI in java. I now wonder what are the solutions chosen by professionals to get a nice GUI, for "real" applications. Do you use swing and JComponents and just change the "look and feel" ? Do you prefer awt or another library ?
Sorry if that question sounds weird, I'm a student and I don't really know how java is used in the real world...

In our company we use Swing, as that is supported by the JVM out of the box, but we do use color coded background colors for some panels and buttons.
If we'd use something different, like SWT or Jambi we'd also have to roll out those frameworks for all platforms, and test those frameworks for all OSses and (supported) java versions. Not nice at all.
It is however fairly tricky to create a nice responsive application with Swing; so you really need to use SwingWorker and the like. With a bit of experience however you can create a nice application that way.
And even if it isn't the fastest framework to develop in, development time is really small compared to defining the functional requirements of the user interface, and testing and support when the version is released.
That said, our target is desktops. If you target mobile devices or also need a web frontend your choices may vary.

I don't believe anyone prefers AWT anymore. Swing supplanted it entirely eleven years ago, building on top of it to correct flaws in the AWT 1.0 design.
Swing isn't the only way that professionals make Java UIs. That works for desktops, but there's also JavaFX now. For the web, UIs are built using HTML, CSS, JavaScript, and JSPs.

My experience is that most organizations that want to create rich GUIs still use Swing, and manually go through all the annoyances of layout managers, etc.
The use of SWT is fairly limited to organizations that are using the Eclipse RCP as their platform. I'm not sure why it hasn't caught on outside this platform.
It's sad to admit, but Java Swing GUIs don't generally look good unless you spend a lot of time creating a more native feel for them. Even then, they often lose out on aesthetics to equivalent programs written specifically for Windows and which use Window APIs like WinForms.

The most decent Apps I saw in the last years were build using Eclipse Rich Client Platform
Eclipse uses the Standard Widget Toolkit
and provides Graphical Editing Framework (GEF)

We typically use Swing becuse it's supported in standard JREs out of the box. Normally we do the initial form design and event hookup in Netbeans and then export it to whatever we wish, Eclipse, for example.
Netbeans spits out pure Java using standard libraries (plus a jar or two you have to include) so it's no big deal designing the form in Netbeans and later moving on to something else.
Some people suggested doing form layout by hand using a layout manager. I see that as an option only if you are doing something big and very well budgeted that has to be maintained ad infinitum. Otherwise it's just too time consuming to be worth it.

We rely on SWT for our Java GUIs. Yes, you have to include an external native library, but the look and feel is native, more responsive (although Swing has become much faster in the past few years) and seamless with other apps on the target platform.

Macintosh OS X creates their own Java runtime. They give Swing components the same look and feel as native applications.
I use strictly Swing. I distribute "real" desktop applications via Web Start for both Mac and Windows that interface with the user's smart card reader.
The NetBeans IDE gives you a WYSIWYG way to create your forms. I've tried it out, and it's pretty neat, but we still use Eclipse as our IDE and design the forms in code.

Related

Java - Styling an application

Okay, i am officially scared to ask this question. I am a PHP developer that is attempting to learn the language of JAVA. My experience limits me to PHP, JavaScript and basic CSS to develop and style my web apps.
I would like to know, and this is embarrassing, What technology is used to "Style" JAVA Applications just like CSS is used to "Style" HTML & PHP applications?
I feel so stupid asking this! Please don't think i am an idiot, i am really good with PHP.
I tried to google the answer but gained more questions than answers.
Web Application using Java:
Frontend is same i.e. HTML/Javascript/CSS
Backend Java (from where data you will get, connect with DB etc etc) similar to role of PHP
Desktop Application:
you can use Java Swing for UI and other API for respective work.
Mobile Application:
use J2ME API for developing application
UI here is developed using JAVA API(only api that are allowed to use under KVM (kilobyte virtual machine)).
For better look and feel there are frameworks for it.
What about JavaFX? As far as I know there are similarities to CSS. However, most of the Java applications are designed to match the system's look-and-feel. That's why tweaking is not as important as to web pages. If you want to start with that, have a look at Swing components. Be aware that JavaFX will be included in Java 8. So JavaFX may be seen as the next gen GUI.
Basically U use JSP/JSF/HTML for front end . There too you can use your CSS skills .. That is CSS can be used for styling ...
Assuming you are doing a desktop application, not internet application - as otherwise PHP and especially HTML/CSS would suffice.
Java Swing is a cross-platform emulation of GUI components. It has so called Look and Feels, one of which is the System L&F, which under Windows tries to look as the Windows GUI. Another is really cross-platform looking: the Nimbus L&F. And there are other Look-and-Feels, even from third parties.
Start with System or Nimbus Look and Feel.
Besides that one might set default colors/fonts for specific type of things. One may query them with SystemColor.activeCaptionText or so. Nice for White on Black.
Inside Swing one uses layouts to do the layouting. Generally not pixel perfect, but with really cross-platform, with consideration for different buttons, menues and such.
Use a GUI editor; I am always advocating the NetBeans IDE, also for its simplicity. Though eclipse is very nice too.
Use separate classes, do not pack all in a GUI class, as that becomes a maintenance mess.
The text components: JLabel, tooltip, and so on, have HTML capabilities: "<html><b>Bold</b><i>Italics</i>".

How can I create a "modern looking" Java desktop application?

Similar questions to this are asked periodically, but many of these answers are outdated.
I need to build a cross-platform desktop application in Java with a GUI of comparable quality to contemporary desktop apps.
Swing is the default choice, but I have yet to encounter a Swing application that didn't look, at the very least, quite dated and clunky (subjective, I know, but with GUIs it's hard to avoid aesthetic judgements).
I notice that the new Bitcoin client now uses QT with Java bindings, and does have an attractive user interface, but this has the disadvantage that it is no-longer pure Java.
So much of what I find when I search for Swing-related libraries is 5 years old or older, even though the aesthetics of desktop applications have evolved significantly since then.
If you needed to build a Java desktop application from scratch, what would you use for its GUI?
I can also offer you a new LaF to look into - WebLaF. I'am currently working on it to bring a lot of UI features and make work with Swing much easier for anyone by just using WebLaF library basic features.
A few examples showing how some of WebLaF components look like:
Some of main goals i am targeting:
Great and modern-looking L&F with support for all Swing components
An extensive set of additional components which you won't find in standard Swing
A big set of Utility classes to assist you with writing the code
WebLaF library also suggests a few other advantages and unique features:
It is an open-source project (GPLv3 licensed)
Easy components styling using painters system (specifically with 9-patch files)
Quick and easy customization of the default "Web" style
Lots of features to accelerate and simplify Swing application interface creation
You can try the demo-app to see if it is modern and simple enough :)
Have you looked into JavaFX 2.0? It is designed to interop easily with Swing, and has many modern 'good looking' controls.
Also, as lrAndroid mentions, a Swing app can look like a native app if you set the system look and feel with:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Look into changing the Look and Feel of your Java program. This allows you to customize the overall "theme" of your program.
Here is information on changing the LAF.
I've had good experiences with FlatLaf.
It's easy to install, it's cross-platform, it has no external dependency, it's open-source (Apache license), it includes dark modes and there are tons of themes.
After adding :
UIManager.setLookAndFeel( new FlatLightLaf() );
your app looks like it was written during the last decade, and not during the previous millenium.
It also has one high-contrast theme, for accessibility.
Modern Javascript frameworks (ExtJS, Dojo, etc...) offer the same widgets richness or more (Excel like grids for instance), a wider variety of L&F and usually fit better with the OS of the user.
Users are also very comfortable with their browsers and, hey, "modern stuff" is on the web, and the modern web today is HTML+Javascript.
The overhead of converting an app to "web like" is minimal. An embedded Jetty can remain really small and disk space has become much less of an issue.
There are additional benefits going down this route for the future evolutions of the application.
Suddenly, the desktop app becomes a server app, which can be accessed from another desktop. We were able top promote a desktop app to 'portal' in a matter of weeks.
Rewriting the app in terms of (Ajax) web services provides an easy transition to creating a full REST (or SOAP...) services stack. The app can then be integrated to other applications, easily monitored externally, etc...
Support of other devices (smart phones, tablets,...) becomes much easier, by concentrating on the UI layer only
As the app grows, separation of concerns is cleaner; developers working on the UI do not have to mess with low level code.
There are a lot of excellent JS/HTML designers and developers that do not program in Java.
EDIT
3 years later this has become extremely easy thanks to Electron
Try one of these:
JTattoo
JGoodies
Quaqua
What about Nimbus look and feel? Oracle Link
Also take a look at SO-Question
I know this question is old, but if you don't want to use FX and still want to use Swing, then try MacWidgets, i've used it on a couple projects. It's very light, and looks great. Below is an old project i was working on, over time i've perfected using macwidgets and now use it internally in my company.
http://www.digitalhand.net/projects/jdataanalyzer/mainGUI.png
QT is quite extensive but also very big (bloated) and complex. There is also the SWT library being used by open office for instance. SWT uses native UI widgets for buttons, tables etc where as Swing emulates them.
However, the trend is clearly towards writing rich client applications for the browser using HTML and Javascript. Both of these have made huge strides in the past few years.
HTML5 specifically targets rich client applications with features such as better forms and local database to support disconnected scenarios (note that this last feature is not standardized yet but it is implemented by all latest browsers).
Javascript has now powerful libraries with jQuery and its many plugins. There are even languages like Coffeescript which can be used to produce Javascript with a simpler and more powerful syntax.
There's also no need for such apps to connect to an outside server. Small footprint local servers (eg: jetty, node.js, ...) and databases (SQLite, H2,...) can be installed on the client to make a completely self contained application.
Swing is good (stable, documented, supported until 2026). The problem is that it relies on the LookAndFeel system that provide a very limited number of boilerplate choices. It should be easy to change the appearance of each component individually and then unleash its creativity. Unfortunately it is painful. IMHO frameworks should be built on top of Swing to make it possible instead of creating JavaFX.
Take a look at https://github.com/dotxyteam/ReflectionUI.
Ex GUI: http://javacollection.net/reflectionui/wp-content/uploads/2017/08/general.png
Go for Jetpack Compose for Desktop. It's a super modern reactive UI which is nice to work with. It also works the same as it would for Android with very few exceptions. It's Kotlin though instead of Java, but these are both JVM based and it's very easy to make the jump.

What should I choose SWT or Swing to program GUI in Java?

I need to create a GUI application in Java. I just realized that I have different optional ways to go (SWT and Swing are among them).
I have already found out that there is a lot of discussions about what way is better and I do not want to go to deep into these discussions (I am a newbie).
I do not care about all aspects of the dilemma. I just have a few main requirements listed bellow:
It should be easy to use (easy to create what I want).
In the end I would like to have just one file which can be easily executed (without any additional tricks, settings and installations) like a standalone application.
It should be platform independent. Or more specifically, the application should work fine on Microsoft-Windows and Ubuntu (Linux).
Based on your requirements, I would say Swing. SWT has a more platform-specific look about it but Java ships with Swing built-in, there's no messing about with external libraries as with SWT although the use of Eclipse may make that much easier (I still develop quite a bit of my stuff from the command line unfortunately).
They're both easy in terms of use (well, easy once you get used to layout managers) and will work fine under both your desired platforms but since the only differentiator you seem to care about is the "without any additional tricks, settings and installations", I would stick with Swing.
That's my advice. Feel free to accept or ignore or even call me an old coot. I won't take offence :-)
I just completed a two year project creating a buisiness application, so my focus was clearly on usability and speed.
My decision in the end clearly led to SWT, for the following reasons:
Buisiness users tend to use Terminal Servers and RDP for their apps. Every Swing app is very slow over RDP, because the app has to render every pixel again and again. Try using Photoshop or Gimp over RDP and start scrolling in an image. That is the performance you have with Swing in tables.
Some very good gui components are only available as COM objects. I wanted to be able to use those, and since 100% of all buisiness customers are Windows users, they accept the fact that your software only runs on Windows. (We have linux clients, too, but only for machine input terminals, that don't need the full blown Windows GUIs)
We use SWTDesigner as a GUI designer, which is as good as SwingDesigner für Swing (which both are the best GUI designers at all). They are worth the price tag if you have to create a few hundred masks.
Our GUI looks 100% native, honors the large fonts they use on their desktops, and feels fast.
We are very satisfied with SWT, but it has some downsides:
Native Java components are a bit rare. There is more on the Swing side of life.
I would suggest that you use Java's Swing libraries if you are not familiar with Java GUI development. They are very well documented, and there are lots of tutorials on-line, including on Sun's Java website (here).
GUI development in Java is not very straightforward, but the tools available are getting better all the time. I would suggest you try out the NetBeans IDE that has a nice visual designer for GUI components. I have not used the Eclipse IDE's GUI designer, but I gather its good as well. You will need to get your head around the MVC pattern, but it should be a good learning experience.
In short, my vote goes for using Swing/JFC, especially if you are new to Java GUI development.
EDIT - You can control the look and feel of a Java APP very easily. If you use the platform independent (Metal) look and feel, your GUI will look pretty much identical on Windows and on Linux. Of course, a Java app will run just fine on Windows of *nux as long as there is a supported JVM installed.
I cannot add comment yet because I'm new here (please mod me up so I can comment) but choosing Swing or SWT depends on the IDE you're using.
If you're using Eclipse, then both are fine.
If you're using the free IntelliJ IDEA community edition, you'll prefer to use Swing because the IDE's GUI editor is "Swing only".
I take it you're using Eclipse?
Based on your requirements, I recommend using Swing:
SWT requires additional native libraries (violates item #2),
You are likely to find more instructional material on Swing (since you are a newbie),
Both solutions are somewhat platform independent and supported on both platform you mentioned but SWT is not equally supported on all platforms,
There are more WYSIWYG tools supporting Swing which may help with the learning curve.
Note that the APIs are similar and sometimes identical so learning one gives you a head start on the other.
I find Netbeans' drag and drop visual editor and pre-wired Swing Desktop Application template much easier to use that what comes bundled with Eclipse, so I'd suggest that.
It'll automatically create an executable jar, and let you create a Java Web Start launcher if you wish as well. And being Java, it's OS-independent.
Here's a link to the quickstart tutorials.
Swing,
SWT works on Ubuntu but not nearly as well as on Windows, that's at least my experience. The main reason to choose SWT is if you want to build your application on the Eclipse RCP framework( where you get a dockable views/editors, plugin mechanism, automatic updates, user roles. help browser, preference mechanism etc) or if you want your application to have that polished native look.
From my experience, if you want easy to develop Swing is the way to go. If you need good performance, then SWT is a better bet.
NOTE: The last time I did GUI development in Java was 4 years ago.

Which tool is Prefered to design a GUI .? Java or .net C# WPF

I want to know which is the best tool which can be used to make GUI . Currently I'm working on VC++ 6.0 and I can't give a good look(Vista Look) in that.
So can anyone help me which one will be more suitable for GUI .. Java or any other tool(.net WPF) and if you can give the reason then it is very helpful.
Thanks
I would recommend WPF .. It has the new markup language which suits well the UI development, supported by code behind.
Check some examples http://blog.trivadis.com/blogs/manuelmeyer/archive/2008/06/12/cool-wpf-samples.aspx
Java is designed to work well across multiple systems.
.NET underlies Windows.
If you're trying to imitate Vista's look and feel as closely as possible, go with the framework that was written by the same company that also made your operating system.
Any of the above are capable of a good "Vista" look (including VC++). You just need to opt-in to the new visual control styles with a manifest. WPF will have the most options for a "sexy" Windows UI, and won't need the manifest.
You can use WPF for serving your purpose. WPF lets you
edit the opacity of the elements : so that you can create transparency effect as in Vista
create storyboards for your animations
change the look and feel of existing controls using styles, so it can be easy to create Vista style controls
apply bitmap effects such as Outerglow, Dropshadow, etc.
Although WPF is not limited to the above features, but it is the partial list of features for which you can use WPF to achieve your desired effect.
If you do decide to go down the Java route, take a look at the JGoodies libraries. They take a lot of the pain out of writing Swing apps by providing (amongst other things) a much more usable layout manager, a data binding framework, and some some Windows like look & feels.
Take a look at this to see why you don't want to use one of Swing's standard layout managers directly...
Depends on what you mean by "best" tool.
In Java you are most likely looking at Swing to develop your application as far as frameworks go. If you are looking for a complete RCP, you could take a look at the Netbeans Platform or Eclipse RCP. The Netbeans IDE also has a nice GUI editor that can be used for generating Swing GUIs (if you don't mind working with generated code and the Netbeans IDE).
WPF is very nice but has quite a large learning curve.
Swing is a bit chunky.
7 years ago at least Delphi was a really really polished and good way to produce a windows GUI, since then Delphi has moved to be a .net laungage. So I would recommend at least looking into Delphi
The tool decision should follow your requirements.
Do you need a GUI for a stand-alone Application or a client-server architecture? If it's stand-alone, do you need it for a single operating system or you need it portable? If it's client-server, do you want a thin client ('webapplication') or a rich client, if it's a rich client, you want the user to install it or shall it be provided by a webservice?
Do you want to hardcode the GUI or declare it? Do you have some expert knowledge on a certain programming language or a certain framework or do you want to use the project to learn on or the other (or both)?
I think, it's much easier to recommend something when we have some more background information.
From the few things I know I suggest:
Upgrade your visual c++ environment and keep working with the tools and frameworks you already know. Microsoft products should be the best solutions to develop applications for Microsoft operating systems.
I would recommend Flex with Adobe AIR - it's nice! adobe flex

JavaFX in the wild?

Does anybody know of any real-world web applications based on JavaFX? I'm an experienced Java programmer considering starting a website while I'm not at my day job. I don't have a lot of expertise on the UI side, so I'm looking for the best way to leverage my existing skills to create something that can provide an awesome RIA experience. Only trouble is, I don't know of any sites that are implemented using JavaFX, since it's so new. I'd like to see what it's capable of.
Found here quite an interesting stories. Top two listed below.
TweetBox
TweetFX
I think the best example of what JavaFX can do is in the examples on JavaFX.com.
However, it's still early in the JavaFX days thus you will be in pioneer days. Which means there are potential rich rewards to be had, but also - many unknowns.
What I think JavaFX "sweet-spots" are:
1 - If you either have Photoshop skills or are collaborating with someone who is - JavaFX provides the only real platform that lets you take Photoshop and generate a UI. Normally you mock-up in Photoshop and try your best to replicate, JavaFX can leverage it natively.
2 - You get all of the goodies from Java libraries "for free".
3 - Can leverage the UI skills to mobile (those that JavaFX will run on anyway).
However, if you are just wanting to have a Java GUI but would rather wait for more polish on JavaFX - I would recommend grabbing MigLayout & go with Swing on Java 6u10 or later.
There are a few JavaFX apps from the JavaFX Coding Challenge; my personal favorite is Music Explorer FX.
The new version of Indaba Music's software was written in JavaFX; the old version was in Flash.
In my personal opinion I would not use JavaFX for web. Simply because HTML5 is crushing everyone in sight. Now, I totally recomend the use of JavaFX for desktop applications.

Categories