I've been a zone leader with DZone since 2008, and I'm crazy about community. Every day I get to work with the best that JavaScript, HTML5, Android and iOS has to offer, creating apps that truly make at difference, as principal front-end architect at Avego. James is a DZone Zone Leader and has posted 639 posts at DZone. You can read more from them at their website. View Full User Profile

Java Swing Components: Bringing Your Swing UI Back To Life

  • submit to reddit

Last week, I discovered a set of Java Swing Components based on a tweet from Kirill Grouchnikov. It's a long time since I saw something new in the Swing space, so  I took a look at the components and contacted the lead developer for the project, Rhiannon Liebowitz, to find out more about his component set, and his plans for it's future. 

DZone: What is your experience with Swing?

Rhiannon: I first encountered Swing while I was working for a large financial organization. The organization was planning to build a banking application to be deployed into more than a dozen countries in Africa. This was quite a few years ago, and bandwidth would be one of the largest constraints we would encounter. As a result a thick Java client was decided upon (as the data transferred by a thick client is much more efficient than an HTML web based system) and I was lucky enough to be one of the first developers assigned to the project.

During my years on the project I was responsible for building a large number of custom Swing components as well as developing various frameworks on which the application relies. It was during this time that I came to love Java and Swing. My favorite aspect of Swing is its flexibility; it gives you the power to build almost any component.

DZone: What motivated you to create these components?

Rhiannon: There were essentially three factors that motivated me to create the initial set of components. First, I wanted to show that Swing components can be visually impressive. Second, I wanted to build components that would be useful to all Swing developers. Third, I wanted to fill a gap in the functionality that exists in the standard Swing libraries.

Working as a Swing developer I noticed that one of the most common frustrations encountered by developers (and business analysts alike) is the inability of the standard JLabel to wrap text, handle line breaks or mix fonts and colors without the inclusion of HTML. Personally I am against the inclusion of HTML in a label’s text as I feel it violates the MVC pattern, pollutes the label’s text and results in string parsing. To make matters worse, trying to perform rule based formatting by generating HTML tags to be included in a label’s text opens a particularly nasty can of worms.

The Wrapping Label was created to address all of these issues, and it does so by making use of a formatting rule engine. The engine processes a list of rules defining how a string should be rendered and applies the rules to a string during the painting process. This keeps the label’s text totally separate from its formatting.

The Accordion was also intended to fill a gap in the swing library. Most other libraries (particularly web based libraries) come standard with an Accordion type component. However, unlike the Wrapping Label, the Accordion gave us the opportunity to really make an impressive looking component and demonstrate how great swing can look. The Accordion, although extremely similar to a JTabbedPane, can be more practical in certain circumstances. An Accordion excels at making the most use of limited horizontal space. When a JTabbedPane is constrained horizontally, the tabs get placed one on top of another and can become hard to read. An Accordion does not suffer from this problem.

One of our goals is to develop a set of components to be used on dashboards and widget libraries. Not only is the Analog Clock the first component of this set, but it is also a component that does a great job of adding a touch of polish to desktop applications. The clock paints itself using a layered approach, thereby making it extremely easy to tweak and customize to the developers needs.

Can you give us some example of how to use the components?

Rhiannon: A great example illustrating the power of the Wrapping Label and its rule based formatting engine, would be to render an approximation of the JAVALOBBY logo.  

To achieve this I will create a new Wrapping Label and then apply the following formatting rules to the label:
1.    The word ‘JAVALOBBY’ should appear blue using size 38, Cambria font.
2.    The first letter should be size 43.
3.    The first occurrence of the word ‘heart’ should appear red and underlined.
4.    The characters ‘(TM)’ should always appear as a superscript.

One of the greatest advantages of the formatting engine is the ability for developers to create and add their own rules in order to cater for even the most unique scenario.

The code below demonstrates how to create the label and apply the rules.

The output above has been achieved without the use of any HTML, resulting in the label’s text remaining pure

DZone:  What are your plans for future development?

Rhiannon: We have a number of new components in various stages of development. Our next scheduled component for release is a date picker (calendar) control.

Future components include:
•    Hyperlinks
•    Auto complete text boxes
•    Digital clocks
•    5 Star rating components
•    Additional sets of borders and separators
•    And many many more.

One of the greatest challenges we are facing at the moment is to prioritize the development of our components to best suit the needs of the Java community. We would love to hear from swing developers out there who have a need for any new type of components.

DZone: What do you think of JavaFX?

Rhiannon: I must admit that JavaFX does look extremely promising and intrigues me greatly; however at present I have not allocated it enough time for the attention it deserves. Having spent most of my time developing banking software, I have learnt to be relatively risk adverse when it comes to new and bleeding edge technology, and as a result I like to wait a few years for a platform to stabilize and entrench itself in the community before I devote substantial time to it.

Do you think there is a decline in Java desktop application development, with both Swing and SWT at the moment?

Rhiannon: I definitely feel (over the years) that there has been an upswing in the popularity of web based development at the expense of desktop development. However, I still feel that to build truly rich and responsive applications, the desktop is the only way to go.

Another consideration that I feel is often overlooked is that in a surprising large number of the world’s countries, high speed bandwidth is actually a luxury, enjoyed by very few. In theory rich web based applications can be accessed from anywhere in the world, however the truth is that there are many people simply don’t have the bandwidth to use them. A thick client communicating over HTTP (or some other protocol) will always outperform a web based application, as it will only send data it needs and will not include any formatting tags. Just think how much wasted data is used to send an HTML table, with all its <tr> and <td> tags.

I truly believe that Swing is the one of the best gui toolkits available for any developer who wants to build a cross platform application, and I think many developers will be programming in Swing for many years to come.

Article Resources: 


Andrew McVeigh replied on Tue, 2010/08/17 - 8:04am

the components are excellent, and very attractive.  lots of options.  well done!

Pascal Lalonde replied on Tue, 2010/08/17 - 9:06am

I agree, web applications are really cool, but enterprise applications aren't required to use them, thin clients do work pretty well and most of "Ordinary people" fell a lot more safe working on this than using web applications. I feel that those rich web applications are more overwhelmed by developers than really the outside world. Great job on those components, I will definitely take a look.

Andy Gibson replied on Tue, 2010/08/17 - 1:16pm

Nice components, Swing and Desktop Development is something I would love to get into more thoroughly coming from a Delphi background originally. However, I never see any demand for it, everything is all web nowadays. The write once, browse anywhere and never upgrade nature of web apps over desktop seems to be a must-have feature which keeps a desktop app out of the picture.


Andy Gibson

Rhiannon Liebowitz replied on Tue, 2010/08/17 - 2:19pm in response to: Andy Gibson

Hey Andy

You are complete correct in saying that web apps are easier to maintain, having a single instance to manage as opposed to many installations on the client is without a doubt one of the best selling point of web development.

However I do think webstart comes to the rescue and does take much of the pain out of maintaining a desktop installed client application.

I think in order to find swing development you need to look in the right places. Speaking from my current environment, I have noticed that quiet a bit of swing development takes place in industries that are not directly (or not often) client facing. I think you will find more swing development in financial, telecom, government and banking related systems. However the primary consumers of these systems tend to be internal staff and not the outside public.






Rhiannon Liebowitz replied on Tue, 2010/08/17 - 2:27pm

We really want to tailor our development efforts to best suit the needs of the swing community and therefore feedback really means a lot to us.

So if anyone has any feedback both positive and negative regarding the current components and site, we really would love to hear from you.

Andrew McVeigh replied on Wed, 2010/08/18 - 4:36am in response to: Rhiannon Liebowitz

hi rhiannon, i really like the current components, but have an idea for a future one. how about a tool palette widget? i ended up making my own for my current project, which was painful as it's a deviation from what i actually do. SWT has a great one, but not swing.

the jhotdraw svg editor palette (not the standard jhotdraw one) is pretty good, but needs more options. it could be a good start.  http://www.randelshofer.ch/oop/jhotdraw/index.html



Rhiannon Liebowitz replied on Wed, 2010/08/18 - 12:09pm in response to: Andrew McVeigh

Hi Andrew, A palette component does indeed sound like a good idea, and we can definitely add it to our backlog of components to be developed. If you know of other developers who would also be interested, I'm sure we could prioritize its development. If you have any more ideas or other suggestions it would be great to hear from you. Rhi

Mike P(Okidoky) replied on Wed, 2010/08/18 - 8:34pm

I've written gui after gui since '99, all Swing and deployed through Webstart. There are some very impressive third party components, from companies like Jidesoft, which offers one of the most sophisticated components in the industry.
I love Miglayout. I'd wish that an xml or json style gui resource framework, like a refined swixml, was part of Swing. But it's not, and the right people seem to not put the right technologies together. Things often becomes a mess, and people end up not liking Swing.
One thing I don't like about swing is how you're not supposed to feed it data outside the awt event thread. Tons of code out there that does, and it causes erroneous behavior.
While the world is trying to cramp and shoehorn everything into the browser using html/javascript, and soon html5 with svg and those other new html5 features, Java people can do much better with Swing, the *right* libraries and technology choices, and Webstart (which needs fixing because of nasty cache bugs that has as of yet still not been fixed...)
Perhaps it's not feasible to reliably deploy Webstart applications to the wider public, but for intranet and specialized purposes, Java/Webstart/Swing is very much superior than that clumsy html crap.

Rhiannon Liebowitz replied on Thu, 2010/08/19 - 3:07am in response to: Mike P(Okidoky)

Hi Mike My feel about the threading in swing, is that yes it is single threaded, but this is not unique to swing and many other gui toolkits are exactly the same. Dealing with the threading is not as tough as it used to be. The swing worker makes it really easy and if you check my blog out, there is an article on how to write a threaded action listener that takes much of the pain out of threading, maybe give it a look. http://www.javaswingcomponents.com/blog/taming-swing-threads-part-4-simplifying-threading-actionlisteners My take on swing is that sun (er... Oracle) focussed on making the library extremely flexible. Once the flexibility was in place, (it seems to me) that they built the component library up to a usable minimum, with the assumption that if someone wanted special or advanced behavior, that they would simply code it themselves. I think the people who will take swing further, will most likely not be Oracle (who currently is focused on JavaFX) but rather third party developers like Java Swing Components, Jidesoft and the other players.

Mike P(Okidoky) replied on Fri, 2010/08/20 - 10:41am in response to: Rhiannon Liebowitz

The mistake I think they made, was that they didn't evolve it further. In order for Swing to have materialized in the first place, there must have one helluva momentum within the Swing team. But then, it stopped cold. Bug fixes and performance enhancements followed, but not further enhancing perfecting.
The community could have, and did, create enhancements, addons, etc. But the problem with the community at large, is that people are not paying attention, do not become aware, are not actively engaged. Certain excellent efforts went unnoticed. Swixml for instance was something worth much more attention. Sun could have helped by highlighting certain third party components, and assimilate certain other ones. MigLayout (although it does need a little refinement), could have been added. People complain about lack of layouts. MigLayout solves a lot of layouts. A combination of swixml, html-ish, miglayout, could make for a much more powerful layout engine.
Now we're seeing Swing and JavaFX combined, which is interesting. Problem is, these efforts are going completely unnoticed. It's like everyone is living inside an isolated shell. People are not aware what others are doing. Either there is too much stuff out there, or the marketing efforts are insufficient.

Witold Szczerba replied on Mon, 2010/08/23 - 7:03pm

Another consideration that I feel is often overlooked is that in a surprising large number of the world’s countries, high speed bandwidth is actually a luxury, enjoyed by very few. In theory rich web based applications can be accessed from anywhere in the world, however the truth is that there are many people simply don’t have the bandwidth to use them. A thick client communicating over HTTP (or some other protocol) will always outperform a web based application, as it will only send data it needs and will not include any formatting tags. Just think how much wasted data is used to send an HTML table, with all its <tr> and <td> tags.


Oh my, this is SO UNTRUE. I was developing applications with Swing front-end since 2006 and I was thinking like Rhiannon, without noticing the browsers changed since the beginning of WWW a lot.

Today you can create entire applications by simply loading just only one - first page and drive all the content from there by AJAX calls, adding and removing DOM nodes dynamically (try jQuery to see how simple it can be). You can use, i.e. JSON datasources (gzipped if you care about bandwidth) and create dynamic tables and forms in browsers run-time - which means extra compact messages between browser and server (forget about sending HTML over the wire if you think it is waste of bandwidth).

More than that - after years of server side and client side (WebStart) Java development I can say - JavaScript together with CSS and HTML is much easier (better) for creating 99% of all the data-driven applications front-end features.

There are tools like Firebug aiding in rapid GUI sketching, there are tools like Selenium for end-to-end automated tests, and finally - there are tools like JsTestDriver for test-driven desing using JavaScript. To see new version of your application, all you need is to refresh a page. You can add [go back]/[go forward] buttons handling, so when someone opens something new - you can close it/reopen it using those buttons, or you can simply disable them if you do not like this conception.

You might ask - OK, and what about that 1% of an application the WWW browser cannot handle? Like, i.e.: client-side generating (ODF, MsOffice?) documents and then launching default application for reading/printing it, and then maybe auto-uploading modified version, and then... No problem. For such a special tasks - embed signed Java Applet (can be hidden) and ask it to do such a work - just as you would do this in typical Java desktop application.

Rhiannon Liebowitz replied on Tue, 2010/08/24 - 3:13am in response to: Witold Szczerba

Hi Witold I am not disrespecting web development or arguing that it is worse than desktop development they are different technologies aimed at different solutions. I can see your point that web development has advanced much in the past few years, and yes you can come extremely close to the same performance while transmitting data. My argument is that even through you can come close, pure serialization of data using a thick client should result in a tighter data packet. Desktop applications fill a different role to web based applications. Lets be honest, we are not online all the time and I personally would not appreciate it, if all my applications were dependent on an internet connection. Imagine always needing an internet connection to run eclipse, netbeans, office or watch a movie. Traveling and flights would become even more painful than they already are. In summary, yes you can do much in a web base application that you can do on a thick client, but they are different beasts all together and there will be come scenarios where web based makes sense and other scenarios that a thick client makes sense.

Darren Martin replied on Tue, 2014/04/08 - 5:27am

Thanks, I thought I could ask help again from my friend but good that you have shared the guide. This is what I exactly need. Is there any animation other than that to include so the UI will be more lively?

"now works at http://www.digiteksf.com/direct-mail/"

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.