Monday, October 12, 2009

Griffon Tip: Silly SwingBuilder Tricks

Here's two quick tips for working with radio buttons in SwingBuilder. Radio buttons are created using SwingBuilder's radioButton() method. To ensure only one is selected at a time, you must also associate them with a button group. Ideally SwingBuilder would allow you to nest your radioButton()s inside a buttonGroup(), e.g.

Unfortunately this doesn't work as buttonGroup() does not support nesting. Marc Hedlund stumbled across this same issue and offers up one solution. I like his solution but it means creating a separate variable to hold the button group. I've found a bit nicer way to do it using Groovy's with keyword:

The only thing I can think of with your mutual binding issues is are you using version 0.2 of Griffon? I can't remember when mutual binding was officially added but this example has been tested on 0.2.

Hey Josh,thank you for blogging, your stuff helps me a lot and is really appreciated! I thought I had installed the latest Version but in fact I did not. So updating to 0.2 solved this and other problems.