Before Christmas I decided to give the Groovy Swing Builder a go since I am in the market for a language that makes creating small utilities in Java easier. Groovy is now Groovy 1.5, fully aligned with the Java 1.5 release. The new release sees lots of improvements all over the place. The Groovy Console has had a substantial revision and is now a really good way of experimenting with more complicated scripts (previously I only really used it to run snippets of code). The text colouring and decoration really works and the previous problems with massive stack traces obscuring actual issues seem to have been fixed. Really there are just two things that are needed to make it perfect, the first is line numbers so you can relate error messages back to the script you are working on and auto-completion. I wouldn’t mind having tabbed editors in the console as well but I can live without it.
What hasn’t changed is that documentation is generally woeful and examples and tutorials are hard to find. Most of the Swing examples I could find really used small numbers of components and simple Layout Managers. I have tried to create a more complex example using Grid Bag and based around some existing Swing code I found.
It took me a lot longer than I thought it would to create this code. Part of this is just not knowing how to tackle things, Groovy allows you to set attributes within the constructor with the interesting syntax property: value
. However it is hard to know when you should use this or when the interaction should occur within the braces. After getting a working example going there is only one major mystery to me here. If I do not put the table inside the scroll pane then I lose the header columns on the table in the second tab. I really cannot see why that should be and if anyone more versed in the language can help me I would be grateful.
Doh! To answer my own question this is my weakass Swing-fu and nothing to do with Groovy. These two tutorials cover the details: How to use Scroll Panes and How to use Tables.
thank you so much for this – I’m having fits trying to find documentation on groovy swing applications and what the syntax is for using different layouts.
i really appreciate you posting this – I think I get the drift of how to do gridbag with groovy