Swing is Especially Effective If...
- You know your target domain or business logic, so that you are able to design expressive and concise domain objects.
- 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.
- 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.
- 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.
- The use of TableCellRenderers and TableCellEditors in JTables helps you to visualize you domain objects directly - without any overhead.
- You are using visual designers like e.g. Matisse in pragmatic way and separate the generated, from your code.
- 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).
- 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.
- 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.
- 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
(2 votes)
- Login or register to post comments
- 5958 reads
- Printer-friendly version
(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
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: Yeray
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