Getting Started with Swing MVC Development on Griffon
Griffon is to the desktop what Grails is to the web. (And its 0.0 release was today.) That's more or less all that needs to be said about it, if you're familiar with Grails. If you're not, Griffon is an MVC framework for Swing applications, using "convention over configuration" for its source structure and Groovy as its language. It's new and fun, in the same way that Grails is.
Here's some recent (colorfully titled) reading, i.e., all of it published in the last 24 hours or so:
- Danno Ferrin: Announcing Griffon
- Andres Almiray: Griffon takes flight
- James Williams: Awakening the Griffon
- Guillaume Laforge: Griffon shows its claws
So much being similar to Grails, creating tools for Griffon is as simple as tweaking the tools for Grails. Here's the NetBeans project template that sets up the source structure by calling "griffon create-app":
Complete the wizard and here's your application, looking similar to Grails, of course:
Let's look at those three files. First, an empty model:
import groovy.beans.Bindable
class HelloGriffonModel {
}
Then, a controller:
class HelloGriffonController {
// these will be injected by Griffon
def model
def view
}
Finally, the view:
application(title:'HelloGriffon', pack:true, locationByPlatform:true) {
// add content here
label("Content Goes Here") // deleteme
}
Run it and you see this:

Now, let's do something with the model:
import groovy.beans.Bindable
class HelloGriffonModel {
@Bindable def greeting = "Hello world"
}
Then, we'll change the view to show the above simple message in our label:
application(title:'HelloGriffon', pack:true, locationByPlatform:true) {
// add content here
label(text:bind {model.greeting})
}
That's all. Just run it and you'll have your static message replaced by the text set in the model. Next, see the Griffon Quick Start for details on creating your own initial application based on the above. The NetBeans Groovy Editor comes in handy:
Three cool samples are part of the Griffon distro, in the "samples" folder. I simply opened them in the IDE (i.e., thanks to "convention over configuration", NetBeans IDE knows exactly what a Griffon application consists of, so there's no import process, no NetBeans project metadata is added to the source structure, one simply opens it via the tweaked Grails modules for NetBeans IDE):
For example, the "GrailsSnoop" sample lets you browse the Grails documentation in a Swing application:
However, in addition to a Swing application, thanks to the "griffon run-app" (i.e., in my case, I simply choose "Run" inside NetBeans IDE) you also have a JNLP application, as well as an applet:
That's not bad! Here's wishing this new framework all the best! I'm also hoping that there will be many more Grails-like frameworks coming out. The Grails approach really gives one the very best of all worlds in hiding the complexities beneath DSLs, Groovy as your language (with all the advantages that that brings, such as not needing to throw out all your Java books), MVC as the structure and the possibility to use different widget sets (in fact, one of the samples uses JIDE, specifically, com.jidesoft.swing.TristateCheckBox).
And what about the tools I showed above? I.e., the integration with NetBeans IDE? Once the NetBeans Grails support has been officialy released as part of 6.5, i.e., all those tools will then be stable, I will fork them and provide a new set of plugins for Griffon.
| Attachment | Size |
|---|---|
| fig-1.png | 47.58 KB |
| fig-2.png | 22.32 KB |
| fig-3.png | 3 KB |
| fig-4.png | 68.54 KB |
| fig-5.png | 30.05 KB |
| fig-6.png | 78.01 KB |
| fig-4.png | 79.01 KB |
| fig-7.png | 33.67 KB |
- Login or register to post comments
- 10519 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
Sidewinder replied on Thu, 2008/09/11 - 8:48pm
This is awesome!, Imagine using JRE6_10 and Griffon, for create RIA's or desktop apps with this will rock, Im just waiting the GORM integration.
Regards.
nicpillinger replied on Mon, 2008/11/17 - 5:59am
excellent work - any chance we can get the netbeans plugin before 6.5 is released? I'm eager to get cracking with Griffon and it makes things so much easier to be developing in netbeans. cheers.
Uggs replied on Sat, 2009/04/25 - 9:45pm
------------------------------------------------------
Ugg Boots | Mortgage Rates | UGGS
piaono1 replied on Sat, 2009/05/23 - 10:22am
rodgerlvu2009 replied on Mon, 2009/05/25 - 7:40pm
rodgerlvu replied on Fri, 2009/05/29 - 3:21am
quick comment to say thank you sir..<a href="http://www.tiffanyworld.co.uk">Tiffany Co.</a>,<a href="http://www.tiffanyworld.co.uk">Tiffany jewellery</a>,<a href="http://www.tiffanyworld.co.uk">Tiffanys</a>
Seeker01 replied on Fri, 2009/06/05 - 7:06am
Seeker01 replied on Fri, 2009/06/05 - 4:31pm
in response to: rodgerlvu2009
abby1 replied on Mon, 2009/06/15 - 8:39pm
emad964 replied on Wed, 2009/06/17 - 7:45pm
beladona replied on Sat, 2009/06/20 - 7:16am
in response to: Uggs
tagshow replied on Wed, 2009/06/24 - 2:37am
sam2009 replied on Thu, 2009/07/02 - 9:50am