Can anybody recommend a (preferably open-source) framework for decoupling GUI from model in Java desktop applications?
-
1Great answer (from Pascal Thivent) **aldready** exists here: http://stackoverflow.com/questions/2105121/what-to-use-mvc-mvp-or-mvvm-or In few words: > MVC is for components, MVP is for applications – Destroyica Sep 11 '11 at 22:46
5 Answers
Fundamentally decoupling a GUI model from your core java code is best done with a databinding library. Which is to say you have your pojo business code, you have the GUI component code, and you don't fancy writing a load of logic to sync them up all the time whilst updating the view and implementing the business logic. So don't. Find a mature databinding framework for the GUI widgets you are using and learn that; have it keep the screen controls in sync with your pojo code.
JGoodies and beanbindings are good examples of Swing variants of binding onto an OO model. The core bits of JGoodies are opensource. If you go to /articles on the jgoodies site it has articles on pattern and databinding. Whilst each binding framework has different classes the patterns for writing good clean code are portable between GUI frameworks and bindings frameworks.
If you download the now opensource WindowsBuilderPro tool then it has excellent examples in both Swing and SWT of doing good databindings. The swing jphonebook example uses the beanbindings library. WindowsBuilderPro is a drag and drop GUI builder; you used to have to pay for it as a leading drag and drop GUI builder which works with the leading free GUI libraries. It was bought by google and opensourced so that they could beef up its graphical screen builder support for GWT (the Google web GUI framework).
That GUI builder tool has both excellent sample code and is an excellent opensource tool now. It does the same example of a phonebook in both Swing and SWT GUI libraries to demo its drag-and-drop GUI builder tool power. So it is a great way to compare and contrast Swing to SWT whilst learning databindings.

- 6,321
- 5
- 58
- 86
I would strongly suggest you to try the ZK framework. I have not found until today such a srtong framework. In my company we have applied new projects within a few weeks using the latest patterns like MVVM. The style of programming is much like developing a classic 'desktop' app.
PS: I am in no way related to the ZK people. I am just using their framework.

- 31
- 1
-
1I love ZK.. but it's a web framework. The question called for a framework for desktop applications. – Sean Connolly Dec 30 '12 at 01:16
Java Swing actually makes good use of MVC for just this purpose.

- 131,333
- 52
- 229
- 284
-
2"Model" in MV* for me means primarily domain model, which ListModel, TableModel and friends certainly aren't; they correspond more closely to a Presenter or a ViewModel. – Alexey Romanov Jun 04 '10 at 22:01
-
2How is a generic framework going to supply a domain specific model component? – Stephen C Jun 05 '10 at 00:30
-
It isn't, of course. I am merely suggesting they've got the name a bit wrong :) – Alexey Romanov Jun 05 '10 at 03:01
From your reaction to the suggestion that Swing is an MVC framework for desktop apps, I think that you really need some kind of generator framework that will generate the 'model' and 'view' code from higher level specifications. Examples I'm (more or less) familiar with are Eclipse EMF, GEF and related technologies.

- 698,415
- 94
- 811
- 1,216