The following procedures build a simple application that displays the same structure data in two table widgets; one in row-major format and one in column-major format.
This example is included in the file table_widget_example2.pro in the examples/doc/widgets subdirectory of the IDL distribution. Run this example procedure by entering table_widget_example2 at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT table_widget_example2.pro. See Running the Example Code if IDL does not run the program as expected.
PRO table_widget_example2_quit_event, ev
WIDGET_CONTROL, ev.TOP, /DESTROY
END
PRO table_widget_example2
d0={planet:'Mercury', orbit:0.387, radius:2439, moons:0}
d1={planet:'Venus', orbit:0.723, radius:6052, moons:0}
d2={planet:'Earth', orbit:1.0, radius:6378, moons:1}
d3={planet:'Mars', orbit:1.524, radius:3397, moons:2}
data = [d0, d1, d2, d3]
labels = ['Planet', 'Orbit Radius (AU)', 'Radius (km)', 'Moons']
max_strlen = strlen('Orbit Radius (AU)')
maxwidth = max_strlen * !d.x_ch_size + 6
base = WIDGET_BASE(/COLUMN)
table1 = WIDGET_TABLE(base, VALUE=data, /COLUMN_MAJOR, $
ROW_LABELS=labels, COLUMN_LABELS='', $
COLUMN_WIDTHS=maxwidth, /RESIZEABLE_COLUMNS)
table2 = WIDGET_TABLE(base, VALUE=data, /ROW_MAJOR, $
ROW_LABELS='', COLUMN_LABELS=labels, /RESIZEABLE_COLUMNS)
b_quit = WIDGET_BUTTON(base, VALUE='Quit', $
EVENT_PRO='table_widget_example2_quit_event')
WIDGET_CONTROL, base, /REALIZE
col_widths = WIDGET_INFO(table1, /COLUMN_WIDTHS)
WIDGET_CONTROL, table1, COLUMN_WIDTHS=col_widths[0], $
USE_TABLE_SELECT=[-1,-1,3,3]
WIDGET_CONTROL, table2, COLUMN_WIDTHS=col_widths[0], $
USE_TABLE_SELECT=[-1,-1,3,3]
XMANAGER, 'table_widget_example2', base
END
The following things about this example are worth noting:
- By default, column and row titles will contain the index of the column or row. To remove either column or row titles entirely, set the value of the COLUMN_LABELS or ROW_LABELS keyword to an empty string ('').
- Setting the width of the row-title column of the row-major table requires us to select column -1 using the USE_TABLE_SELECT keyword.