Packing Using Tables

Let's take a look at another way of packing - Tables. These can be extremely useful in certain situations.

Using tables, we create a grid that we can place widgets in. The widgets may take up as many spaces as we specify. The first thing to look at, of course, is the Gtk::Table.new method:

Gtk::Table.new  rows, columns, homogeneous

The rows and columns are laid out from 0 to n, where n was the number specified in the call to Gtk::Table.new . So, if you specify rows = 2 and columns = 2, the layout would look something like this:

Figure 3. Table

Note that the coordinate system starts in the upper left hand corner. To place a widget into a box, use the following function:

table.attach widget, left_attach, right_attach, top_attach, bottom_attach

We also have table.set_row_spacing and table.set_col_spacing. These places spacing between the rows at the specified row or column.

table.set_row_spacing  row,    spacing
table.set_col_spacing  column, spacing

Note that for columns, the space goes to the right of the column, and for rows, the space goes below the row. You can also set a consistent spacing of all rows and/or columns with:

table.set_row_spacings spacing
table.set_col_spacings spacing

Note that with these calls, the last row and last column do not get any spacing.