Geertjan is a DZone Zone Leader and has posted 468 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started with Swing MVC Development on Griffon

  • submit to reddit

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:

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.

fig-1.png47.58 KB
fig-2.png22.32 KB
fig-3.png3 KB
fig-4.png68.54 KB
fig-5.png30.05 KB
fig-6.png78.01 KB
fig-4.png79.01 KB
fig-7.png33.67 KB
Published at DZone with permission of its author, Geertjan Wielenga.


John Denver 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.


Nic Pillinger 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. 

David Savage replied on Mon, 2009/09/28 - 3:26am

Having used Grails I now want to port my code over to Griffon, so that I can distribute it as a stand-alone java app. I would love it if all I had to do was code-up the front-end. I'm trying to find out when GORM will be integrated, but haven't found a planned date yet.

Kookee Gacho replied on Mon, 2012/07/02 - 7:11am

Griffon is a type of dog, a collection of breeds of originally hunting dogs. -Arthur van der Vant

Comment viewing options

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