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
  • Overview
  • Source Code
  • Methods
  • References

Was this helpful?

  1. Documentation
  2. Components

Grid

Overview

Grid is a control that contains a list organized by columns, where each column can receive an individual size and an alignment.

Source Code

import totalcross.sys.Settings;
import totalcross.ui.Button;
import totalcross.ui.Grid;
import totalcross.ui.MainWindow;
import totalcross.ui.dialog.MessageBox;
import totalcross.util.UnitsConverter;
import java.util.ArrayList;

public class GridSample extends MainWindow {

    private final int H = 225;
    private ArrayList<User> users = new ArrayList<>();
    private Grid grid;
    private Button loadButton;
    private int GAP = UnitsConverter.toPixels(DP + 8);
    
    public GridSample(){
        setUIStyle(Settings.Material);
    }

    @Override
    public void initUI() {
        String[] gridCaptions = { "Name", "Phone", "Email" };
        int gridWidths[] = { -35, -35, -30 };
        int gridAligns[] = { LEFT, LEFT, LEFT };

        grid = new Grid(gridCaptions, gridWidths, gridAligns, false);
        grid.verticalLineStyle = Grid.VERT_LINE;

        loadButton = new Button("Load");

        add(grid, LEFT + GAP, TOP + GAP, FILL - GAP, FILL - GAP * 9);
        add(loadButton, LEFT + GAP, BOTTOM - GAP, FILL - GAP, PREFERRED);

        loadButton.addPressListener( e -> {

            for (int i = 0; i < 5; i++) {
                users.add(new User("Joao ","99999999","joao@j.com","12345678"));
            }

            if (users.size() > 0) {
                String items[][] = new String[users.size()][3];
                for (int i = 0; i < users.size(); i++) {
                    User user = users.get(i);
                    items[i] = new String[] { user.getName(), user.getPhone(), user.getMail() };
                }
                grid.setItems(items);
            } else {
                MessageBox mb = new MessageBox("Message", "No registered users.", new String[] { "Close" });
                mb.popup();
            }
        });
    }

    public class User {

        private String name;
        private String phone;
        private String mail;
        private String password;

        public User() {

        }

        public User(String name, String phone, String mail, String password) {
            this.name = name;
            this.phone = phone;
            this.mail = mail;
            this.password = password;
        }

        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getPhone() {
            return phone;
        }
        public void setPhone(String phone) {
            this.phone = phone;
        }
        public String getMail() {
            return mail;
        }
        public void setMail(String mail) {
            this.mail = mail;
        }
        public String getPassword() {
            return password;
        }
        public void setPassword(String password) {
            this.password = password;
        }

    }
}

Methods

Type

Name

Description

Constructor

Grid(String[] captions, int[] widths, int[] aligns, boolean checkEnabled)

Captions for the columns. Cannot be null;

Widths of the columns. If the total width is less than the grid's width, the last column will fill until the grid width;

Alignment of information on the given column;

checkEnabled is True if you want the multi-selection check column;

Constructor

Grid(String[] captions, boolean checkEnabled)

Captions for the columns; checkEnabled is True if you want the multi-selection check column;

Void

setItems(String[][] items)

Sets the grid items to be displayed.

Void

setDataSource(DataSource ds, int nrItems)

Sets the data source of this grid to be the given one.

Void

add(String[] item)

Add a new line.

Void

add(String[] item, int row)

Add a new line at the given index position of the grid.

‌

References

PreviousGpiodNextGridContainer

Last updated 5 years ago

Was this helpful?

See the sample.

See the for more information.

github
Java Docs