88 CHAPTER 7. GRAPHICAL USER INTERFACE DESIGN IN SCHEME
Likewise we could use a grid in place of table in this example. Try it and
see how they differ.
There is one other major layout mechanism that is quite useful the border
layout. This layout allows one to put five components on a page. They can go
in the north, south, east, west, and center. When the window is resized, the
center component grows (or shrinks) horizontally and vertically, while the other
components stay near the edges. For example, we could extend the previous
example, by putting the table in the center of a border layout with labels in the
four other positions:
(define w
(window "Hello"
(border
(center
(table 2 2
(label "red" red)
(label "green" green)
(label "yellow" yellow)
(label "blue" blue)
))
(north (label "north" white))
(south (label "south" yellow))
(east (label "east" green))
(west (label "west" red))
)))
(.pack w)
(.show w)
This example also shows how layouts can be nested. Notice that we have put
a table in the center of the border layout. Likewise, we could put a table or
a column in the east or west of the border. Or we could put a grid inside one
of the table entries.
Exercise 18 Build several GUIs with colored labels as above. Try to create
layouts that are nested several levels deep and see what happens when you expand
and contract the window.
7.8
Buttons
Buttons are similar to labels except that you can attach actions to them.
These actions are carried out when the button is pushed. We will discuss actions
in more detail below, but for now we give a simple example. In the following
example, pushing the buttons resizes the window as specified in the label:
(define w
(window "Hello"
(row 'none 'center white
(button "big" red