Programmer's Reference

Check boxes

Check boxes consist of several toggle buttons that present a set of options to the user. The user can choose none, all, or any combination of the buttons. A CwRowColumn widget can be used to contain the buttons. When the row-column's radioBehavior resource is false, its default, more than one toggle button can be selected at a time.

The code that follows creates the toggle-button group shown on the right.

| shell rowColumn button buttonNames initialValues |
shell := CwTopLevelShell
   createApplicationShell: 'shell'
   argBlock: [:w | w title: 'Check Box Example'].
 
rowColumn := shell
   createRowColumn: 'group'
   argBlock: nil.
rowColumn manageChild.


Figure SP007100 not displayed.

buttonNames := #('Item 1' 'Item 2' 'Item 3').
initialValues := (Array with: false with: true with: true).
1 to: buttonNames size
   do: [:i |
      button := rowColumn
         createToggleButton: (buttonNames at: i)
"The state of each toggle button is set on creation according to the 
 corresponding value in the initialValues array. In this example, Item2
 and Item3 are both selected, and this is indicated by an X."
         argBlock: [:w | w set: (initialValues at: i)].
     button
         addCallback: XmNvalueChangedCallback
         receiver: self
         selector: #valueChanged:clientData:callData:
         clientData: nil.
     button manageChild].
shell realizeWidget.

The valueChanged callback used by the code is shown below. A message is written to the transcript whenever a button is selected or deselected.

valueChanged: widget clientData:clientData callData: callData
   "A toggle button has changed state."
   Transcript cr; show: widget labelString, ' has been '.
   callData set
      ifTrue: [Transcript show: 'selected.']
      ifFalse: [Transcript show: 'deselected.'].


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]