# Check

![](https://1246655713-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_mPP3a_E_A7NbRMq7Q%2F-M2DNyCRrop7qXq4ZKZK%2F-M2Dj27AlPLoUP7-ZBgQ%2Fq2.gif?alt=media\&token=f3447019-377a-46fc-bd18-81eb9b736773)

## Examples

TotalCross includes a wide range of modifications for your `Check`, use `Control` methods.

```java
package com.totalcross; 

import totalcross.ui.MainWindow; 
import totalcross.ui.gfx.Color; 
import totalcross.ui.Check; 
import totalcross.sys.Settings;

public class HelloWorld extends MainWindow {
    public HelloWorld() {
        setUIStyle(Settings.MATERIAL_UI);
    }
    
    @Override
    public void initUI() {
        try {
            Check red = new Check("Red");
            Check green = new Check("Green");
            Check blue = new Check("Blue");
    
            red.setForeColor(Color.RED);
            green.setForeColor(Color.GREEN);
            blue.setForeColor(Color.BLUE);
    
            add(red, LEFT+100, CENTER-40);
            add(green, LEFT+100, CENTER);
            add(blue, LEFT+100, CENTER+40);
        } catch (Exception exception) {
            // Handle exception
        }
    }
}
```

![](https://1246655713-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_mPP3a_E_A7NbRMq7Q%2F-M2DNyCRrop7qXq4ZKZK%2F-M2E-gKswipvF1bnQWxA%2Fq4.gif?alt=media\&token=a657c3d0-0f07-47ee-80c1-b9a8607c9ac3)

## Box and text with different colors

In some situations, it may be necessary to use different colors for the box and the text.

```java
package com.totalcross; 

import totalcross.ui.MainWindow; 
import totalcross.ui.gfx.Color; 
import totalcross.ui.Check; 
import totalcross.sys.Settings;

public class HelloWorld extends MainWindow {
    public HelloWorld() {
        setUIStyle(Settings.MATERIAL_UI);
    }
    
    @Override
    public void initUI() {
        try {
            Check check = new Check("Check!");
    
            check.checkColor = Color.RED;
            check.textColor = Color.BLUE;
    
            add(check, CENTER, CENTER);
        } catch (Exception exception) {
            // Handle exception
        }
    }
}
```

![](https://1246655713-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_mPP3a_E_A7NbRMq7Q%2F-M2E11ohDIUg7xIh05wo%2F-M2E8Vp33jFjljevQxeR%2FQ6.gif?alt=media\&token=e985ee99-e953-4c08-8074-5542f43ab47e)

## Custom left gap

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

![](https://1246655713-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-L_mPP3a_E_A7NbRMq7Q%2F-M2E11ohDIUg7xIh05wo%2F-M2ECrafVAko81cz6RSH%2FQ8.gif?alt=media\&token=34e5a00c-a50d-429f-92e5-e481834368ab)

## 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**

* See the [JavaDocs](https://rs.totalcross.com/doc/totalcross/ui/Check.html) for more information.
