Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class Table
- Object
- Table
Rows and columns rendered as text, aligned by the columns each cell takes on a terminal, so styled cells, wide characters and emoji line up:
Table table = new Table("Name", "Status", "Size")
.align(2, Table.Align.RIGHT);
table.addRow("api", Console.style("running", Console.Style.GREEN), "12 MB");
table.addRow("worker", Console.style("stopped", Console.Style.RED), "3 MB");
Console.print(table.render());
A table wider than maxWidth (the terminal by default) shrinks its widest
columns and wraps their cells. A cell may hold line breaks.
Nested types
enum Table.Align | How a column’s cells line up. |
enum Table.Border | The lines drawn around and between cells. |
Constructors
public Table(String... headers) | A table with these column headers; none for a table without a header row, whose column count then comes from its widest row. |
Methods
public Table align(int column, Table.Align align) | Aligns column column (from 0). |
public Table border(Table.Border border) | The border style; Border.ROUNDED by default, Border.ASCII when Console.unicode says box drawing is unsafe. |
public Table maxWidth(int maxWidth) | The widest the table may be, in columns; the terminal width by default. |
public Table headerStyle(boolean bold) | Whether the header row is bold (when color is on); true by default. |
public Table addRow(Object... cells) | Appends a row. |
public int rowCount() | The number of rows added so far, header excluded. |
public String render() | The table as text, every line ended by a line break. |
public String toString() | Returns a string representation of the object. |
Inherited methods
Constructor details
Table
public Table(String... headers)A table with these column headers; none for a table without a header
row, whose column count then comes from its widest row.
Method details
align
public Table align(int column, Table.Align align)Aligns column
column (from 0).border
public Table border(Table.Border border)The border style;
Border.ROUNDED by default, Border.ASCII when
Console.unicode says box drawing is unsafe.maxWidth
public Table maxWidth(int maxWidth)The widest the table may be, in columns; the terminal width by default.
headerStyle
public Table headerStyle(boolean bold)Whether the header row is bold (when color is on); true by default.
addRow
public Table addRow(Object... cells)Appends a row. Each value is shown as
String.valueOf gives it; a
row shorter than the table is padded with empty cells.rowCount
public int rowCount()The number of rows added so far, header excluded.
render
public String render()The table as text, every line ended by a line break.
toString
public String toString()Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@’, and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
getClass().getName() + ‘@’ + Integer.toHexString(hashCode())