Fanning Software Consulting

Columns of Equal Width

QUESTION: When I place three buttons with values Apply, OK and Cancel in a one row base widget, the buttons all have a different size. I want them to all have the same size. Can you tell me how to do this?

ANSWER: When a button is created it has a "natural" size that depends upon the text on the button. Buttons size themselves to fit what is on them, normally. You can explicitly size buttons with the Scr_XSize and Scr_YSize keywords, but this is not always a good idea, since people prefer different fonts, different font sizes, etc., and your button interface can end up looking decidedly unprofessional. sometimes want a neat, all-the-same-size look. I know I do.

The easiest way to do this is to use the Grid_Layout keyword to the Widget_Base command.

   grid = WIDGET_BASE (base, COLUMN = 3, /GRID_LAYOUT)
   b1 = WIDGET_BUTTON (grid, VALUE = 'Apply')
   b2 = WIDGET_BUTTON (grid, VALUE = 'OK')
   b3 = WIDGET_BUTTON (grid, VALUE = 'Cancel')

For example, here is a set of buttons with and without the Grid_Layout keyword used on Widget_Base.

Three buttons with and without the GRID_LAYOUT keyword.

Web Coyote's Guide to IDL Programming