Tuesday, August 10, 2004


I ran across this animated weblog entry about GridBagLayout. It reminded me of my own history of using this key GUI class. I doubt if I could be trusted to do anything in anger with the class today, but there was a period of about seven minutes when I felt like I really had a handle on using it.

It was right around the period when I was studying for my Java certification. Back in the old days, GUI design was part of the exam so you had to know all the GUI classes including the layout managers. I used the old "Complete Java 2 Certification Study Guide" by Roberts, Heller, and Ernest plus some supplemental material I had to try to figure out how to use GridBagLayout. I designed a fairly complex GUI on paper and then tried to recreate it using the GUI classes. You have to keep in mind that this was without Swing because Swing was not on the exam.

Anyway, nothing I did looked even remotely like my design. In fact, everything looked like crap. I realized that the only way to do a decent design was to dive in and use every layout manager imaginable in combination. I started with BorderLayout and stuck GridLayout in one section and GridBagLayout in another. Panels were everywhere with their own layout managers inside them. The end result was... crap.

OK, I thought, my company spent thousands of dollars on the enterprise version of VisualCafe. Surely a product that cost this much money should be able to do GUI design with ease. I can do the design in that, I thought, and study the code to see where I am going wrong. So I pop into VisualCafe and start dropping Labels and Panels and TextFields and everything looks beautiful. Except, It looks like crap when I resize it and if I look at the program in any other screen size it looks like crap. Uh-oh... VisualCafe is defaulting to absolute positioning and null layouts. That sucks. No problem... I'll force it to use layout managers and try again. Half a day later, my fields are all scrunched in the corner and the layouts seem to randomly change everytime I touch a key. One last try... I'll bring in the crappy looking design I did by hand and work from there. Nope... VisualCafe continues to randomly change layouts and move fields around, on the rare ocassions when it even recognizes my code as being for a GUI layout.

Back to the drawing board... time to get serious. I spend two days re-reading everything and trying every possible combination of commands that can be used with layouts. GridBagConstraints slowly starts to make sense... fill, anchor, gridwidth, weightx, it all starts to make sense. Layout command are flying from my fingers. Quick change, compile, run... not quite, another quick change without even checking the API, compile, run, and NIRVANA! The screen looks perfect. Resize... still perfect. Different screen size... still perfect. On a Mac.. still beautiful. I took the test a couple of days later and aced the GUI section. And then didn't touch any of this again.

Today I look back at those few moments and wonder what drugs I was taking. Or more to the point, what drugs the designers of the AWT were taking.

1 comment:

Helen said...

The Creative Clowning stage of learning anything new. Nothing goes to plan or behaves properly delivering an awe-inspiring smack to the senses.