Package totalcross.ui

Class Check

  • All Implemented Interfaces:
    MaterialEffect.SideEffect, TextControl

    public class Check
    extends Control
    implements TextControl, MaterialEffect.SideEffect
    Check is a control with a box and a check inside of it when the state is checked.

    Here is an example showing a check being used:

     public class MyProgram extends MainWindow
     {
        Check check;
    
        public void initUI()
        {
           add(check = new Check("Check me"), LEFT, AFTER);
        }
    
        public void onEvent(Event event)
        {
           if (event.type == ControlEvent.PRESSED && event.target == check)
           {
              bool checked = check.isChecked();
              ... handle check being pressed
     
    • Field Detail

      • leftJustify

        @Deprecated
        public boolean leftJustify
        Deprecated.
        Now the align is always at left
        Set to true to left-justify the text in the control. The default is right-justified, if the control's width is greater than the preferred one.
        Since:
        TotalCross 1.0
      • textColor

        public int textColor
        Sets the text color of the check. Defaults to the foreground color.
        Since:
        TotalCross 2.0.
      • checkColor

        public int checkColor
        Set to the color of the check, if you want to make it different of the foreground color.
        Since:
        TotalCross 1.3
      • autoSplit

        public boolean autoSplit
        Set to true to let the Check split its text based on the width every time its width changes. If the height is PREFERRED, the Label will change its size accordingly. You may change the height again calling setRect.
        Since:
        TotalCross 1.14
    • Constructor Detail

      • Check

        public Check​(java.lang.String text)
        Creates a check control displaying the given text.
    • Method Detail

      • onEvent

        public void onEvent​(Event event)
        Called by the system to pass events to the check control.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • setText

        public void setText​(java.lang.String text)
        Sets the text that is displayed in the check.
        Specified by:
        setText in interface TextControl
      • getText

        public java.lang.String getText()
        Gets the text displayed in the check.
        Specified by:
        getText in interface TextControl
      • isChecked

        public boolean isChecked()
        Returns the checked state of the control.
      • setChecked

        public void setChecked​(boolean checked)
        Sets the checked state of the control.
      • setChecked

        public void setChecked​(boolean checked,
                               boolean sendPress)
        Sets the checked state of the control, and send the press event if desired.
      • getMaxTextWidth

        public int getMaxTextWidth()
        Returns the maximum text width for the lines of this Label.
      • getPreferredWidth

        public int getPreferredWidth()
        returns the preffered width of this control.
        Overrides:
        getPreferredWidth in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        returns the preffered height of this control.
        Overrides:
        getPreferredHeight in class Control
      • onColorsChanged

        protected void onColorsChanged​(boolean colorsChanged)
        Description copied from class: Control
        Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
        Overrides:
        onColorsChanged in class Control
      • onPaint

        public void onPaint​(Graphics g)
        Called by the system to draw the check control.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • paintCheck

        public static void paintCheck​(Graphics g,
                                      int fmH,
                                      int height)
        Paints a check in the given coordinates. The g must have been translated to destination x,y coordinates.
        Parameters:
        g - The desired Graphics object where to paint. The forecolor must already be set.
        fmH - The fmH member
        height - The height of the control. The check will be vertical aligned based on this height.
        Since:
        SuperWaba 5.5
      • clear

        public void clear()
        Clears this control, checking it if clearValueInt is 1.
        Overrides:
        clear in class Control
      • split

        public void split​(int maxWidth)
        Splits the text to the given width. Remember to set the font (or add the Label to its parent) before calling this method.
        Since:
        TotalCross 1.14
        See Also:
        autoSplit
      • onFontChanged

        protected void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control
      • onBoundsChanged

        protected void onBoundsChanged​(boolean screenChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)