|
Introduction
Containers Layouts Widgets
|
Layouts -> GridBagLayout[PENDING: Document is not finished]GridBagLayout allows you to virtually divide your frame/container into grids. The total number of grids depends entirely on you. The widgets/components can then be placed in those grids. With GridBag, you can make a widget sit on two grids or more. Grids can be imagined as rows and columns. The image below illustrates the concept of rows and columns. ![]() Widgets can occupy two or more grids (or rows and columns). And with gridbag layout, it is possible to make the widgets resize, expand, or stick to a certain area, depending on the constraints specified (see below). Every widget has to have their own constraints. To setup gridbag layout to a container:
$p = panel('layout=gridbag');
Sample 1, before resizing. ![]() Sample 1, after resizing. ![]() Code for Sample 1.
alias gridbagdemo {
$frame = frame("GridBagLayout Demo", 'center=1');
$panel = panel($frame,'layout=gridbag');
# First row, 2 buttons
$gbcon1 = constr('row=0', 'column=0', 'weightx=0.8', 'fill=horizontal');
$gbcon2 = constr('row=0', 'column=1', 'colspan=2', 'fill=horizontal');
# Second row, 1 textarea, spans 3 columns
$gbcon3 = constr('row=1', 'column=0', 'colspan=3',
'weightx=1.0', 'weighty=1.0',
'fill=both', 'insets=5 1 5 1');
# Third row, 3 buttons
$gbcon4 = constr('row=2', 'column=0', 'anchor=right');
$gbcon5 = constr('row=2', 'column=1');
$gbcon6 = constr('row=2', 'column=2');
add($panel, button('button 1'), $gbcon1);
add($panel, button('button 2'), $gbcon2);
add($panel, textarea('') , $gbcon3);
add($panel, button('button 4'), $gbcon4);
add($panel, button('button 5'), $gbcon5);
add($panel, button('button 6'), $gbcon6);
pack($frame);
show($frame);
}
Sample 2, before resizing. ![]() Sample 2, after resizing. ![]() Code for sample 2.
alias gridbagdemo2 {
$frame = frame("GridBagLayout Demo - Part2", 'center=1');
$panel = panel($frame,'layout=gridbag');
# First row, 2 buttons
$b1 = constr('row=0', 'column=0', 'colspan=2', 'weightx=0.8', 'fill=horizontal');
$b2 = constr('row=0', 'column=2', 'colspan=2', 'fill=horizontal');
# Second row, 1 textarea, spans 4 columns
$t1 = constr('row=1', 'column=0', 'colspan=4',
'weightx=1.0', 'weighty=1.0',
'fill=both', 'insets=5 1 5 1');
# Third row, 1 checkbox, 3 buttons
$c1 = constr('row=2', 'column=0');
$b4 = constr('row=2', 'column=1', 'anchor=right');
$b5 = constr('row=2', 'column=2');
$b6 = constr('row=2', 'column=3');
add($panel, button('button 1'), $b1);
add($panel, button('button 2'), $b2);
add($panel, textarea('') , $t1);
add($panel, checkbox('checkbox 1'), $c1);
add($panel, button('button 4'), $b4);
add($panel, button('button 5'), $b5);
add($panel, button('button 6'), $b6);
pack($frame);
show($frame);
}
constr() refers to constraints. This dictates location of components in the frame, and their behaviour when the frame is resized. Basically, using GridBag would look like this:
$container = panel('layout=gridbag');
$some_widget_constraints = constr(insert properties and values);
add($container, $some_widget, $some_widget_constraints);
| ||||||||||||||||||||||||