LogoLogo
v7.0.0
v7.0.0
  • TotalCross Overview
  • TotalCross Javadoc
  • TotalCross Changelog
  • Roadmap
  • Documentation
    • Getting Started
      • First embedded project with TotalCross
    • Components
      • Accordion
      • Aligned Labels
      • Button
      • Check
      • ComboBox
      • Dynamic Scroll
      • Edit
      • Floating Button
      • Gpiod
      • Grid
      • GridContainer
      • Image
      • ImageControl
      • ImageList
      • Label
      • Material Icons
      • Material Window
      • MessageBox
      • Multi Edit
      • Progress Bar
      • Progress Box
      • Radio
      • Radio Group
      • Scroll Container
      • Side Menu
      • Slider
      • Sliding Window
      • Spin List
      • Spinner
      • Switch
      • Tabbed Container
      • Velocimeter
    • APIs
      • API Overview
      • API Rest
      • Asynchronous Task
      • Camera
      • Control
        • Main Window
        • Window
        • Container
      • GPS
      • HTTPS and SSL
      • JSON
      • Maps
        • Maps - Deprecated
        • Static Map
      • Material Design Standards
      • Ninepath
      • Notifications
      • PrinterManager
      • Push Notification Firebase
      • Scanner
      • SOAP
      • Socket
      • SocketServer
      • SQLite Encryption
      • QR Code Generator
      • totalcross.sys
      • Youtube API
    • Creating an Issue
    • Contributing
      • Branch workflow
      • Writing documentation
    • Guides
      • App Architecture
        • Suggested Architecture
        • Why do Design Patterns help with the application's organization?
          • MVC Architecture Pattern
          • Template Pattern
          • Data Persistence: DAO Pattern.
        • Separation of concepts: What is the best way to create UI interfaces?
        • Positioning
          • Manual Positioning
        • Relative Positioning
        • Best practices to improve project maintenance
      • Device Simulator
      • Package your app from scratch
        • TotalCross SDK
        • Environment Variables in IDE
          • Eclipse
          • IntelliJ
        • Deploy your app with a dependecy TC
        • Deploy iOS
          • Using Development certificate to test your apps
      • Understanding TotalCross for Linux ARM
      • Running C++ applications with TotalCross
      • Web Services
    • Miscelaneous
      • Java JDK 8
      • Maven
      • Installing Visual Studio Code
    • FAQ
      • IMEI in Android 10
Powered by GitBook
On this page
  • Examples
  • Label shape
  • Behind the Class
  • Attributes
  • Methods
  • References

Was this helpful?

  1. Documentation
  2. Components

Label

This control is used to display static text or a marquee. The label in TotalCross can also display multiple lines of text, separated by the character.

PreviousImageListNextMaterial Icons

Last updated 5 years ago

Was this helpful?

Examples

This is the simplest example for label.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Label;
import totalcross.ui.MainWindow;

public class LabelSample extends MainWindow  {
    public LabelSample(){
        setUIStyle(Settings.MATERIAL_UI);
        Settings.uiAdjustmentsBasedOnFontHeight= true;
    }

    public void initUI(){
        Label helloWord = new Label("Hello World!");
        //helloWord.setText("text");
        add(helloWord, CENTER, CENTER);
        }
}

Label shape

Modify the shape of the component.

package com.totalcross;
import totalcross.sys.Settings;
import totalcross.ui.Label;
import totalcross.ui.MainWindow;
import totalcross.ui.gfx.Color;
public class LabelSample extends MainWindow{

    public LabelSample(){
        setUIStyle(Settings.MATERIAL_UI);
        Settings.uiAdjustmentsBasedOnFontHeight =  true;
    }

    public void initUI(){
        Label lb1, lb2, lb3, lb4;
        lb1 = new Label("This is a Simple Label", CENTER);
        lb1.setBackForeColors(Color.BLUE,  Color.WHITE);
        add(lb1, CENTER, CENTER, PARENTSIZE +  70, PREFERRED +  20);

        lb2 = new Label("This is a 3D Label", CENTER);
        lb2.setBackForeColors(Color.BLUE,  Color.WHITE);
        lb2.set3d(true);
        add(lb2, CENTER, AFTER +  20, SAME, SAME);

        lb3 = new Label("This is a Inverted Label", CENTER);
        lb3.setBackForeColors(Color.BLUE,  Color.WHITE);
        lb3.setInvert(true);
        add(lb3, CENTER, AFTER +  20, SAME, SAME);

        lb4 = new Label("This is a Label with a large text and line break", CENTER);
        lb4.setBackForeColors(Color.BLUE,  Color.WHITE);
        lb4.autoSplit = true;
        add(lb4, CENTER, AFTER +  20, SAME, 50);

    }

}

Behind the Class

Attributes

Type

Name

Description

int

Align

Sets the text align as LEFT, RIGHT, CENTER and FILL(justified)

boolean

autoSplit

Set to true to let the label split its text based on the width every time its width changes

Methods

Type

Name

Description

Constructor

Label( )

Creates an empty label, using FILL as the preferred width

Constructor

Label(String text)

Creates a label displaying the given text (that may be changed at runtime) using left alignment. Supports inverted text, multiple lines and is scrollable by default

Constructor

Label(String text, int align)

Like the above, but you can also set the horizontal alignment using one of the constants LEFT, CENTER, RIGHT, or FILL (justified)

void

setInvert( )

Inverts the back and fore colors

void

setHighlighted( )

Highlights the text by painting the text in all directions with a brighter color, then centered, with the foreground color.

void

setHighlightedColor( )

Sets the color used when highlighting is on

void

set3d(boolean on)

Draws the label with a 3d effect

References

See the for more information.

See the

Label Java Docs
Video tutorial