Adding Checkmarks Menu Selections
QUESTION: I would like to add a checkmark next to a pull-dowm menu selection to indicate the currently selected item. Is this possible in IDL?
![]()
ANSWER: Yes, it's possible as of IDL 5.6. In Windows, a checkmark is used as the indicator. In Motif, a selection box is used. You can create checkmarks on buttons that are part of a pull-down menu system or that are part of a context-sensitive menu system. The secret is to set the CHECKED_MENU keyword when you create the button widget. This will enable checkbox selection, although the button will not be displayed with a checkmark unless the button is specifically set. The button is set in the normal way with WIDGET_CONTROL and the SET_BUTTON keyword.
Here is a short example program.
PRO Checkmarks_Events, event
; Get the current button selection.
Widget_Control, event.top, Get_UValue=currentSelection
; Unselect the old current button, and select the new
; current button.
Widget_Control, currentSelection, Set_Button=0
Widget_Control, event.id, Set_Button=1
; Update and store the current selection.
currentSelection = event.id
Widget_Control, event.top, Set_UValue=currentSelection
END ;-----------------------------------------------------
PRO Checkmarks
; Create the widgets. Set the CHECKED_MENU keyword on buttons
; that will allow checkmarks.
tlb = Widget_Base( title = 'Checkmark Test Program', XOffset=50, YOffset=50)
menuButton = Widget_Button(tlb, /Menu, Value='Pull-Down Menu', $
Event_Pro='Pull_Down_Menu_Events', Scr_XSize=150)
catID = Widget_Button(menuButton, Value='Cat', /Checked_Menu)
dogID = Widget_Button(menuButton, Value='Dog', /Checked_Menu)
coyoteID = Widget_Button(menuButton, Value='Coyote', /Checked_Menu)
frogID = Widget_Button(menuButton, Value='Frog', /Checked_Menu)
; Save the current button so it can be stored internally in UVALUE.
current = coyoteID
; Put a checkmark on the current button.
Widget_Control, current, Set_Button=1
; Realize and run the program.
Widget_Control, tlb, /Realize
Widget_Control, tlb, Set_UValue=current
XManager, 'Checkmarks', tlb, /No_Block
END
Running the program results in the look (on Windows) shown in the figure below.

Ben Tupper provided a glimpse of what a checkmark looks like on a Macintosh computer in this figure. He recommends if you can't see the little dot by the "One" that you wash the donut greese off your monitor first.

![]()
Copyright © 1997-2004 David W. Fanning
Last Updated 12 July 2004