Search…
Check
Box that can be filled with a check. Build powerful forms!

Examples

TotalCross includes a wide range of modifications for your Check, use Control methods.
1
package com.totalcross;
2
3
import totalcross.ui.MainWindow;
4
import totalcross.ui.gfx.Color;
5
import totalcross.ui.Check;
6
import totalcross.sys.Settings;
7
8
public class HelloWorld extends MainWindow {
9
public HelloWorld() {
10
setUIStyle(Settings.MATERIAL_UI);
11
}
12
13
@Override
14
public void initUI() {
15
try {
16
Check red = new Check("Red");
17
Check green = new Check("Green");
18
Check blue = new Check("Blue");
19
20
red.setForeColor(Color.RED);
21
green.setForeColor(Color.GREEN);
22
blue.setForeColor(Color.BLUE);
23
24
add(red, LEFT+100, CENTER-40);
25
add(green, LEFT+100, CENTER);
26
add(blue, LEFT+100, CENTER+40);
27
} catch (Exception exception) {
28
// Handle exception
29
}
30
}
31
}
Copied!

Box and text with different colors

In some situations, it may be necessary to use different colors for the box and the text.
1
package com.totalcross;
2
3
import totalcross.ui.MainWindow;
4
import totalcross.ui.gfx.Color;
5
import totalcross.ui.Check;
6
import totalcross.sys.Settings;
7
8
public class HelloWorld extends MainWindow {
9
public HelloWorld() {
10
setUIStyle(Settings.MATERIAL_UI);
11
}
12
13
@Override
14
public void initUI() {
15
try {
16
Check check = new Check("Check!");
17
18
check.checkColor = Color.RED;
19
check.textColor = Color.BLUE;
20
21
add(check, CENTER, CENTER);
22
} catch (Exception exception) {
23
// Handle exception
24
}
25
}
26
}
Copied!

Custom left gap

Increase or decrease the spacing between box and text try check.textLeftGap = 20

Responsive text split

Have more responsive texts using check.autoSplit = true. Useful for applications that deal with resizing

Behind the Class

Attributes

Type
Name
Description
boolean
autoSplit
Set to true to let the Check split its text based on the width every time its width changes
int
checkColor
Set to the color of the check, if you want to make it different of the foreground color
int
textColor
Sets the text color of the check
int
textLeftGap
Set gap size between check box and text

Methods

Type
Name
Description
Constructor
Check(String Text)
Creates a check control displaying the given text
Boolean
isChecked( )
Returns the checked state of the control
String
getText( )
Gets the text displayed in the check
void
setChecked(boolean checked)
Sets the checked state of the control
void
setChecked(boolean checked, boolean sendPress)
Sets the checked state of the control, and send the press event if desired
void
setText(String text)
Sets the text that is displayed in the check
void
split(int maxWidth)
Splits the text to the given width

References

Last modified 1yr ago