Re: Designing Graphic Interfaces
Posted: Dec 25, 2003 5:42 PM
> RADICAL, at <a href="http://radical.sourceforge.net/">
> provides a new layout
> manager that works like a grid with adjustable
> heights and widths. I suspect that's a good
> thing, because as clever as nested layout managers
> seemed in theory, they turn out to be a bear to
> work with in practice -- the complexity basically
> overwhelms your ability to predict what's going to
> happen to the layout when you resize the window, and
> you wind up having to do a lot of coding to handle
> that seemingly simple task.
The first complicated GUI development that I did was building user interfaces for TCL/TK applications. The TK packer is a simple command that has powerful capabilities for rectangular/grid type layouts.
The Java GridBagLayout has the same capabilities, but it has an absolutely horrible programming API. The gridbag contraints data object makes the whole API feel like a windows programming exercise.
I created a new wrapper class, called Packer, that provides a TCL/TK like interface. In TCL/TK, one would encode a layout using
pack .top.frame.label1 -gridx 0 -gridy 0 -west
pack .top.frame.field1 -gridx 1 -gridy 0 -fillx
that would create a labeled text field that expanded horizontally when the outer frame size changed.
Using my Packer class, you would do something like
JPanel p = new JPanel();
Packer pk = new Packer(p);
to associate the container with the Packer instance. Then, you'd use that Packer instance as
pk.pack( new JLabel("Field") ).gridx(0).gridy(0).west();
pk.pack( new JTextField() ).gridx(1).gridy(0).fillx();
This is the only layout that I have used since 1996 when I put it together. When you have multiple horizontal components stacked, or multiple vertical components displayed horizontally, you should always put an empty JPanel() at the end of the list and use filly() or fillx(), respectively, if you want the objects to be pressed against the opposite "wall".
Packer is out on java.net for those that might be interested in it. All the GUI layout and building tools that I've used have been worthless because of their code generation model. I've seen a wide range of code models from inline coding with tags delimiting user added code, to stub methods for event processing, to subclassing as well as listeners everywhere.
I've always resorted back to hand coded GUI layout because it really does allow me to do exactly what I need, with certain optimizations in code to handle things like building tables of controls or otherwise generating many instances of a similar control with minor differences. With most GUI tools, I'd have to edit 10s of property sets to change something simple like borders, whether there is a ':' at the end of all labels etc.
I'll have to look at Radical to see what's up...