Radio buttons are created in groups known as matrixes. They take quite a bit more setting up in code. The handler here takes a list of button titles, the usual size values, and a boolean for whether they should run vertically or horizontally. They can be configured to have both columns and rows, but that's a complication we will live without. So without further to-do, here's the code:
on makeMatrix:listOfNames leftInset:theLeft bottom:theBottom maxWidth:theWidth isVertical:isVertical
set theCount to count of listOfNames
if isVertical then
set rowCount to theCount
set colCount to 1
else
set colCount to theCount
set rowCount to 1
end if
set theDepth to rowCount * 18 + (rowCount - 1) * 2 -- 18 pts per button + 2 pts between
set theMatrix to current application's NSMatrix's alloc()'s initWithFrame:(current application's NSMakeRect(theLeft, theBottom, theWidth, theDepth)) mode:(current application's NSRadioModeMatrix) cellClass:(current application's NSButtonCell) numberOfRows:rowCount numberOfColumns:colCount
set theCells to theMatrix's cells() as list
repeat with i from 1 to count of theCells
((item i of theCells)'s setButtonType:(current application's NSRadioButton))
((item i of theCells)'s setTitle:(item i of listOfNames))
end repeat
theMatrix's setIntercellSpacing:(current application's NSMakeSize(8, 2))
theMatrix's setAutorecalculatesCellSize:true
theMatrix's sizeToCells()
set newSize to theMatrix's frame()'s |size|()
theMatrix's setFrameSize:{width of newSize, theDepth}
return {theMatrix, theBottom + theDepth, width of newSize}
end makeMatrix:leftInset:bottom:maxWidth:isVertical:
And because matrixes normally carry labels, this handler will build a labeled matrix, with the label to the left and aligned vertically with the first button. As with popups and checkboxes, you can also align on the first button by passing a value for matrixLeft that is greater than the leftInset value.
on makeLabeledMatrix:listOfNames leftInset:theLeft bottom:theBottom maxWidth:theWidth label:theLabel matrixLeft:matrixLeft isVertical:isVertical
if matrixLeft ≤ theLeft then
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:theWidth alignment:"left" multiLine:false
set matrixLeft to (newWidth + 6)
set {theMatrix, theTop, theWidth} to my makeMatrix:listOfNames leftInset:matrixLeft bottom:theBottom maxWidth:(theWidth - newWidth - 6) isVertical:isVertical
else
set {theLabel, theTop, newWidth} to my makeLabel:theLabel leftInset:theLeft bottom:(theBottom + 2) maxWidth:(matrixLeft - theLeft - 6) alignment:"right" multiLine:false
set {theMatrix, theTop, theWidth} to my makeMatrix:listOfNames leftInset:matrixLeft bottom:theBottom maxWidth:(theWidth - matrixLeft) isVertical:isVertical
end if
theLabel's setFrame:(current application's NSOffsetRect(theLabel's frame(), 0, theTop - theBottom - 18))
return {theMatrix, theLabel, theTop, matrixLeft}
end makeLabeledMatrix:leftInset:bottom:maxWidth:label:matrixLeft:isVertical:
And that's it for the controls.