Thursday March 29, 2007
How Cool is Swing in Groovy?
Let's say you wanted to create this GUI:
If you were to sketch this out quite roughly in pseudo code, the content and layout would basically be this:
frame (title:'Demo') {
menuBar {
menu('File') {
menuItem 'New'
menuItem 'Open'
}
}
panel {
label 'Label 1'
slider()
comboBox(items:['one','two','three'])
}
}
frame.show()
Anyone, regardless of their insight into programming, would be able to come up with something like the above. Well, how cool is Groovy? You can literally paste the above into a Groovy context, add a few things to load the SwingBuilder library and pack the frame, and you're done:
When I run the above from the IDE, I get the GUI shown at the start of this blog entry. Given how easy this all is in Groovy, I wonder whether the Groovy community even needs a Matisse-like GUI Builder. It all seems pretty intuitive, and with syntax coloring and code completion, plus maybe one or two other fun things (such as the Navigator shown above), coding Swing in Groovy is going to be a breeze.
By the way, the listing above comes directly from section 8.5 of "Groovy in Action". The section is called "Easy GUIs with SwingBuilder" and, based on my first cursory explorations, that title delivers on its promise. (A second "by the way" is that everything you see in the screenshot above,i.e., this support in NetBeans IDE 6.0 for Groovy, is freely available, if you follow the instructions in my blog entry from yesterday. Currently, it is buggier than the underside of a rock in a desert, but that's why it is a development version.)
Mar 29 2007, 06:32:19 AM PDT Permalink


