Developer Resources
CheckBox
Overview
The CheckBox class represents a check box control.
Base Class
Constructor
- CheckBox(text : String, x_pos : Integer, y_pos : Integer, width : Integer, height : Integer)
Arguments
- text
- The text to be shown next to the control.
- x_pos
- The x position of the control.
- y_pos
- The y position of the control.
- width
- The width of the control.
- height
- The height of the control.
Events
- CheckBox.click
- Fired when the check box is clicked.
Methods
- CheckBox.getLabel
- Gets the text associated with the check box control.
- CheckBox.getValue
- Gets the visible state of the check in the check box control.
- CheckBox.setLabel
- Sets the text associated with the check box control.
- CheckBox.setValue
- Turns the check in the check box on or off.
Inherited Methods
- FormControl.captureMouse
- Captures the mouse on this form control.
- FormControl.disablePaint
- Disables the window from redrawing itself.
- FormControl.enablePaint
- Enables the window to redraw itself.
- FormControl.getBackgroundColor
- Gets the background color of the form control.
- FormControl.getClientSize
- Gets the client size of the form control.
- FormControl.getEnabled
- Indicates whether or not a form control is enabled.
- FormControl.getFont
- Gets the default font for the text of form control.
- FormControl.getForegroundColor
- Gets the foreground color of the form control.
- FormControl.getMaxSize
- Gets the maximum size of the form control.
- FormControl.getMinSize
- Gets the minimum size of the form control.
- FormControl.getMousePosition
- Gets the mouse position relative to this form control.
- FormControl.getNativeHandle
- Gets the native handle of the window/control
- FormControl.getPosition
- Gets the position of a form control.
- FormControl.getSize
- Gets the size of the form control.
- FormControl.invalidate
- Invalidates a form control, which will cause it to be repainted on the next paint event.
- FormControl.refresh
- Refreshes a form control, which immediately repaints the entire form control.
- FormControl.releaseMouse
- Releases the mouse from being captured on this form control.
- FormControl.setBackgroundColor
- Sets the background color of the form control.
- FormControl.setClientSize
- Sets the client size of a form control.
- FormControl.setEnabled
- Enables or disables the form control.
- FormControl.setFocus
- Sets the focus to the form control.
- FormControl.setFont
- Sets the default font for the text of the form control.
- FormControl.setForegroundColor
- Sets the foreground color of the form control.
- FormControl.setMaxSize
- Sets the maximum size of a form control.
- FormControl.setMinSize
- Sets the minimum size of a form control.
- FormControl.setPosition
- Sets the position of a form control relative to the the form control's parent.
- FormControl.setSize
- Sets the size of a form control.
- FormControl.show
- Shows or hides the form control.
- FormControl.update
- Updates a form control, which will immediately repaint any invalid areas.
Example
// create a new checkbox sample form var f = new MyForm("CheckBox Example", 0, 0, 400, 300); f.center(); f.show(); Application.run(); // define the checkbox sample form class MyForm extends Form { var m_textbox; function MyForm(caption, x_pos, y_pos, width, height) { // MyForm() gets called when a new object is created; // the super() function calls the contructor on the // base class, which in this case is Form since MyForm // extends Form super(caption, x_pos, y_pos, width, height); // create checkboxes with various color labels var checkbox1 = new CheckBox("Red"); var checkbox2 = new CheckBox("Yellow"); var checkbox3 = new CheckBox("Green"); var checkbox4 = new CheckBox("Blue"); // create a new line var line = new Line(Line.Horizontal); // create a new textbox; set the member variable // m_textbox to the newly created textbox so we // can output results to the textbox in the event // handler m_textbox = new TextBox(); m_textbox.setMultiline(true); // add the checkboxes to the top part of the form; // use a layout object to space the elements horizontally var layout_top = new BoxLayout(Layout.Horizontal); layout_top.addSpacer(); layout_top.add(checkbox1, 0, Layout.Expand | Layout.Top | Layout.Bottom, 5); layout_top.addSpacer(10); layout_top.add(checkbox2, 0, Layout.Expand | Layout.Top | Layout.Bottom, 5); layout_top.addSpacer(10); layout_top.add(checkbox3, 0, Layout.Expand | Layout.Top | Layout.Bottom, 5); layout_top.addSpacer(10); layout_top.add(checkbox4, 0, Layout.Expand | Layout.Top | Layout.Bottom, 5); // add the checkboxes, line, and the textbox to the form var layout_main = new BoxLayout(Layout.Vertical); layout_main.addSpacer(); layout_main.add(layout_top, 0, Layout.Expand | Layout.Left | Layout.Right, 5); layout_main.addSpacer(10); layout_main.add(line, 0, Layout.Expand | Layout.Left | Layout.Right, 5); layout_main.addSpacer(10); layout_main.add(m_textbox, 1, Layout.Expand | Layout.Left | Layout.Right, 5); layout_main.addSpacer(); // use layout_main for the main form layout setLayout(layout_main); // connect the checkbox events to the event handler checkbox1.click.connect(this, onCheckBoxClicked); checkbox2.click.connect(this, onCheckBoxClicked); checkbox3.click.connect(this, onCheckBoxClicked); checkbox4.click.connect(this, onCheckBoxClicked); } function onCheckBoxClicked(sender, event_args) { // when a checkbox is clicked, output the label and // check status to the textbox if (sender.getValue()) m_textbox.appendText(sender.getLabel() + " checked.\n"); else m_textbox.appendText(sender.getLabel() + " unchecked.\n"); } }
CheckBox.getLabel
- function CheckBox.getLabel() : String
Returns
Returns the text associated with the check box control.
Description
Returns the text associated with the check box control.
CheckBox.getValue
- function CheckBox.getValue() : Boolean
Returns
Returns true if the check in the check box control is visible, and false otherwise.
Description
Returns true if the check in the check box control is visible. Returns false if the check in the check box control is not visible.
CheckBox.setLabel
- function CheckBox.setLabel(text : String)
Arguments
- text
- The text to draw next to the control.
Description
Sets the text associated with the check box control.
CheckBox.setValue
- function CheckBox.setValue(flag : Boolean)
Arguments
- flag
- The state to which to set the check in the check box. If flag is true, the check box will show the check, and if flag is false, the check box will not show the check.
Description
Turns the check in the check box on if flag is true. Turns the check in the check box off if flag is false.