Fanning Software Consulting

Removing Draw Widget Scroll Bars

QUESTION: I initially create a draw widget window with scroll bars to display my image data. But when my user selects a smaller image I would like it to be displayed in a draw widget window without scroll bars. How can I turn scroll bars on and off in this draw widget window?

ANSWER: The short answer is, you can't. Once a draw widget is created with scroll bars, you can't turn those scroll bars off.

What you can do instead is destroy the old draw widget window and create a new one without scroll bars. Destroying widgets when a widget program is running can be a bit disconcerting to the user, so I usually like to put the widget I am destroying into its own base widget. Then I can unmap the base widget, destroy and recreate the widget inside of it, and then remap the base widget when I am finished. This has a better "look and feel" to the user.

Here is an example program that illustrates the technique. To run the program you will need the LoadData and TVImage programs from the Coyote Library. Any image with a size greater than 400 in one of its dimensions is displayed in a window with scroll bars. Any image smaller than this is displayed in a window without scroll bars. You can resize the image by resizing the window, but if you resize the image in one of its dimensions to greater than 400 pixels, you will get a window with scroll bars. Resizing the image (or window) to less than 400 by 400 will result in a window without scroll bars.

Save the file as "", compile it, and type "Scroll_Example" to see it run.

   IDL> .Compile scroll_example
   IDL> Scroll_Example

Try loading different images with it. Any image that is smaller than 400 in both dimensions will be displayed without scroll bars, which those with dimensions greater than 400 will be displayed with scroll bars.

Web Coyote's Guide to IDL Programming