Edit

An Edit is a field used to show and alter texts. Also known as UITextField on Swift and input on HTML. There also is some variations, like Outlined Edit, Calculator Edit, Password Edit, etc.

Examples

In most applications is necessary to remove the background from the object and change the color of the element so that it is better viewed.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Edit;
import totalcross.ui.MainWindow;
import totalcross.ui.dialog.MessageBox;
import totalcross.ui.gfx.Color;
import totalcross.util.UnitsConverter;

public class HelloWorld extends MainWindow {
    private Edit simpleEdit;
    private int GAP = UnitsConverter.toPixels(DP +  15);

    public HelloWorld(){
        setUIStyle(Settings.MATERIAL_UI);
    }  

    @Override
    public void initUI(){
        try{
            simpleEdit = new Edit();
            simpleEdit.caption = "Simple Edit";
            simpleEdit.transparentBackground = true;
            simpleEdit.captionColor = Color.RED;
            simpleEdit.setForeColor(Color.RED);

            add(simpleEdit, LEFT + GAP, AFTER + GAP);
        } catch (Exception e) {
            MessageBox.showException(e, true);
        }
    }
}

Numeric edit

In some situations, entry should be limited to numbers.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Edit;
import totalcross.ui.MainWindow;
import totalcross.ui.dialog.MessageBox;
import totalcross.util.UnitsConverter;

public class HelloWorld extends MainWindow {

    private Edit numericEdit;
    private Edit calculatorEdit;
    private int GAP = UnitsConverter.toPixels(DP +  15);
    
    public HelloWorld(){
        setUIStyle(Settings.MATERIAL_UI);
    }  
    @Override
    public void initUI(){
        try{
            numericEdit = new Edit();
            numericEdit.caption =  "NumericBox Edit";
            numericEdit.setMode(Edit.CURRENCY);
            numericEdit.setKeyboard(Edit.KBD_NUMERIC);  
            add(numericEdit, LEFT + GAP, AFTER + GAP);
            
            calculatorEdit =  new  Edit();
            calculatorEdit.caption =  "Calculator Edit";
            calculatorEdit.setMode(Edit.CURRENCY, true);
            add(calculatorEdit, LEFT + GAP, AFTER + GAP);
        } catch (Exception  ee) {
            MessageBox.showException(ee, true);
        }
    }
}

Password Edit

If the entry is a password, it should not be possible to see it.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Edit;
import totalcross.ui.MainWindow;
import totalcross.ui.dialog.MessageBox;
import totalcross.util.UnitsConverter;

public class HelloWorld extends MainWindow {
    private Edit passwordShowEdit;
    private Edit passwordHidenEdit;
    private int GAP = UnitsConverter.toPixels(DP +  15);

    public HelloWorld(){
        setUIStyle(Settings.MATERIAL_UI);
    }  
    @Override
    public void initUI(){
        try{
            passwordShowEdit = new Edit();
            passwordShowEdit.caption = "Password Edit (last character is shown)";
            passwordShowEdit.setMode(Edit.PASSWORD);
            add(passwordShowEdit, LEFT + GAP, AFTER + GAP);
            
            passwordHidenEdit =  new  Edit();
            passwordHidenEdit.caption =  "Password Edit (all characters are hidden)";   
            passwordHidenEdit.setMode(Edit.PASSWORD_ALL);
            add(passwordHidenEdit, LEFT + GAP, AFTER + GAP);
        }catch (Exception  ee) {
            MessageBox.showException(ee, true);
        }
    }
}

Edit shapes

To receive different input formats, which are not predefined in TotalCross.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Edit;
import totalcross.ui.MainWindow;
import totalcross.ui.dialog.MessageBox;
import totalcross.util.UnitsConverter;

public class HelloWorld extends MainWindow {
    private Edit calendarEdit;
    private Edit timerEdit;
    private Edit maskedEdit;
    private int GAP = UnitsConverter.toPixels(DP +  15);

    public HelloWorld(){
        setUIStyle(Settings.MATERIAL_UI);
    }  

    @Override
    public void initUI(){
        try{
            calendarEdit = new Edit("99/99/99");
            calendarEdit.caption =  "Calendar Edit";
            calendarEdit.setMode(Edit.DATE, true);
            add(calendarEdit, LEFT + GAP, AFTER + GAP);

            timerEdit = new Edit("99"  + Settings.timeSeparator +  "99"  + Settings.timeSeparator +  "99");
            timerEdit.caption = "TimeBox Edit (24-hour format)";
            timerEdit.setValidChars("0123456789AMP");
            timerEdit.setMode(Edit.NORMAL, true);
            timerEdit.setKeyboard(Edit.KBD_TIME);
            add(timerEdit, LEFT + GAP, AFTER + GAP);

            maskedEdit = new Edit("999.999.999-99");
            maskedEdit.caption = "Masked Edit (999.999.999-99)";
            maskedEdit.setMode(Edit.NORMAL, true);
            maskedEdit.setValidChars(Edit.numbersSet);
            add(maskedEdit, LEFT + GAP, AFTER + GAP);
        }catch (Exception  ee){
            MessageBox.showException(ee, true);
        }
    }
}

Behind the Class

Attributes

Methods

References

Last updated