Java Champion / JavaOne Rockstar Adam Bien (adam-bien.com) is a self-employed consultant, lecturer, software architect, developer, and author in the enterprise Java sector. He is also the author of several books and articles on Java and Java EE technology, as well as distributed Java programming. adam has posted 59 posts at DZone. View Full User Profile

Swing is Especially Effective If...

11.26.2008
| 6932 views |
  • submit to reddit


  1. You know your target domain or business logic, so that you are able to design expressive and concise domain objects.


  2. You are thinking in "swing models", not the UI-components. If you understand your domain, you probably have an idea as well how to visualize the business concepts in object oriented way. The use of Swing models just becomes natural.


  3. You are starting with the domain objects covered with unit tests, then develop the Swing models - after that the work is almost complete. You "only" have to create the view and pass the model to it.


  4. You are NOT trying to work with the views directly and force them to behave in your way. This could become quite complex, cumbersome and very hard to maintain. E.g. if you are working with the JTable directly, instead of TableModel, even reordering the table columns can cause you some headaches. The are no issues with a custom model in this case.


  5. The use of TableCellRenderers and TableCellEditors in JTables helps you to visualize you domain objects directly - without any overhead.


  6. You are using visual designers like e.g. Matisse in pragmatic way and separate the generated, from your code.


  7. You have a clear concept how to bind (e.g. with reflection+annotations or JSR-295) the UI-components to domain objects and how and where to validate the input (e.g. in controllers, domain objects or converters).


  8. Try to leverage existing JavaBean patterns like PropertyChangeListener, PropertyChangeSupport and the already built-in listeners in the UI-components. There is lot of stuff which can be reused.


  9. If you spend more than half hour to solve a specific "Swing-problem", just stop hacking and use google to find a solution for your problem. There are amazingly good tutorials, articles and posts out there.


  10. If you lose your motivation. Just stop developing Swing, build a quick prototype with SWT/JFace for few hours (but use Tables and Trees). Your motivation should increase dramatically after this experiment :-)

From: Adam Bien's Weblog

Published at DZone with permission of its author, adam bien.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

Mike P(Okidoky) replied on Wed, 2008/11/26 - 11:49am

Although there are definitely some quircky aspects and issues with Swing, Swing has seen a lot of unjustified verbal abuse. Distortion and lies, much of it.

It works. It's not slow, and with a good look and feel plugged in, it can look fantastic.

I think what's been missing is a trend of using layout definition files, like Swixml.

It might be useful to start a new topic on Swing and the definite best way to make Swing ui's.

Andy Leung replied on Wed, 2008/11/26 - 12:57pm

I agree on all these but particularly on #10!!!  LOL...

Adrian A. replied on Thu, 2008/11/27 - 6:50am

I would add:

#11. Use something like JFormDesigner for an hour (there is a trial version), to quickly make some advanced and scalable UI. The first question that will pop out will be: why do we(are we forced to) make web applications all the time when a Swing one would be much faster and better? :).

Andy Leung replied on Thu, 2008/11/27 - 12:45pm

@a_adrian:

 That's because both desktop and web applications satisfy different needs.  Web is like thin client but for applications you need something that is processed or stored offline.  For example, if you are a sales person who has access to laptop on the road without internet, you need a desktop application to store your information until you hit the internet cafe, then you can VPN back and sync back your sales data.

I understand this example is old, we are in 2008 (counting 31 days to be in 2009 :) ) but we also have to understand that not all companies are in the wonderland yet.  Until we have full coverage of internet across all continents, there are always times that users may not have internet access but still need to store data, so there you have desktop application.

BTW, a browser is a desktop application that can "cache" data on local disk when it is running offline.  So Google Desktop is not a web application entirely.

Just my 2 cents.

Santana Borges replied on Fri, 2008/11/28 - 11:11am

Hi,

My problem with swing applications is how to get a correct separation of model and view. There are a good article in java.sun

http://java.sun.com/developer/technicalArticles/javase/mvc/index.html

 Do you know another good article or guide for develop swing applications with model-view-cotroller pattern?

 

Java Guy replied on Sat, 2008/11/29 - 3:07am in response to: Santana Borges

It's not free, but it's worth it...

 Desktop java live by scott delap

http://www.lulu.com/content/120769 

 

he goes in depth w/ code samples on mvc, mvp(presenter) with good solid code samples

Comment viewing options

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