See: Description
| Interface | Description |
|---|---|
| V1_TablePair<LHS,RHS> |
A pair of things, with a left and a right hand side (or left and right).
|
| V1_TableTheme |
Interface for themes of table borders.
|
| Class | Description |
|---|---|
| V1_AsciiTable |
Original ASCII table with flexible column number, column width, wrapping, spanning and themes.
|
| V1_Factory |
Factory for common table artifacts.
|
| Enum | Description |
|---|---|
| V1_CharactersBoxDrawing |
ASCII and UTF-8 box drawing characters.
|
| V1_StandardTableThemes |
Predefined render themes for the ASCII table.
|
n columns.
Width set either as overall table width with equally distributed column widths or as fixed width per column.
A table can be rendered using a table theme.
A set of themes is pre-defined, additional themes can be defined as needed.
newTable(Integer, Integer)
V1_AsciiTable at = V1_AsciiTable.newTable(3, 76); will create a new table with 3 columns with 24 characters width each.
The remaining 4 characters (to table width of 76) are used for vertical lines.
n columns and a fixed width set per columns: newTable(Integer[])
V1_AsciiTable at = V1_AsciiTable.newTable(new Integer[]{10, 20, 30}); will create a new table with 3 columns, where column 1 has a width of 10 characters, column 2 has a width of 20 characters and column 3 has a width of 30 characters.
The overall table has then a width of 64 characters (60 characters for the columns plus 4 characters for vertical lines).
addRow(Object…) can be used to add rows to it.
Finally, call render() render the table into a string.
To change the appearance of the rendered table use setTheme() and setPaddingCharacter().
The table theme determines the borders of the table.
The default theme is V1_StandardTableThemes.PLAIN_7BIT.
A number of themes are provided in V1_StandardTableThemes, including light, double and heavy UTF-8 character boxes and LaTeX style table themes.
Individual themes can be created by creating a class implementing the V1_TableTheme interface.
The padding character is used to pad content lines in table rows.
The default is blank (␣). Themes and padding characters are applied per render call, enabling a table to be rendered multiple times with different options.
V1_AsciiTable at = V1_AsciiTable.newTable(3, 76);
at.addRow(null, null, "Table Heading");
at.addRow("first row (col1)", "with some information", "and more information");
at.addRow("second row (col1)", "with some information (col2)", "and more information (col3)");
System.out.println(at.render());
The output of this example will be:
+--------------------------------------------------------------------------+
| Table Heading |
+------------------------+------------------------+------------------------+
|first row (col1) |with some information |and more information |
+------------------------+------------------------+------------------------+
|second row (col1) |with some information |and more information |
| |(col2) |(col3) |
+------------------------+------------------------+------------------------+
Integer[] to initialize the table.
The table again has 3 rows and 3 columns, but this time column 1 is set to 10 characters, column 2 is set to 15 characters and column 3 is set to 20 characters:
Integer[] columns = new Integer[]{10, 15, 20};
V1_AsciiTable at = V1_AsciiTable.newTable(columns);
at.addRow(null, null, "Table Heading");
at.addRow("row 1", "this is col 2", "and this is column 3");
at.addRow("row 2", "some text for column 2", "and some text for column 3");
System.out.println(at.render());
The output of this example will be:
+-----------------------------------------------+
| Table Heading |
+----------+---------------+--------------------+
|row 1 |this is col 2 |and this is column 3|
+----------+---------------+--------------------+
|row 2 |some text for |and some text for |
| |column 2 |column 3 |
+----------+---------------+--------------------+
V1_StandardTableThemes.LIGHT and then render the table:
at.setTheme(V1_StandardTableThemes.LIGHT);
at.render();
System.out.println(at.render());
The output will now be:
┌───────────────────────────────────────────────┐
│ Table Heading │
├──────────┬───────────────┬────────────────────┤
│row 1 │this is col 2 │and this is column 3│
├──────────┼───────────────┼────────────────────┤
│row 2 │some text for │and some text for │
│ │column 2 │column 3 │
└──────────┴───────────────┴────────────────────┘
If we use the theme V1_StandardTableThemes.DOUBLE, the output should look like this:
at.setTheme(V1_StandardTableThemes.DOUBLE);
at.render();
System.out.println(at.render());
The output will now be:
╔═══════════════════════════════════════════════╗
║ Table Heading ║
╠══════════╦═══════════════╦════════════════════╣
║row 1 ║this is col 2 ║and this is column 3║
╠══════════╬═══════════════╬════════════════════╣
║row 2 ║some text for ║and some text for ║
║ ║column 2 ║column 3 ║
╚══════════╩═══════════════╩════════════════════╝
If we use the theme V1_StandardTableThemes.LIGHT_DOUBLE, the output should look like this:
at.setTheme(V1_StandardTableThemes.LIGHT_DOUBLE);
at.render();
System.out.println(at.render());
The output will now be:
╒═══════════════════════════════════════════════╕
│ Table Heading │
╞══════════╤═══════════════╤════════════════════╡
│row 1 │this is col 2 │and this is column 3│
╞══════════╪═══════════════╪════════════════════╡
│row 2 │some text for │and some text for │
│ │column 2 │column 3 │
╘══════════╧═══════════════╧════════════════════╛
If we use the theme V1_StandardTableThemes.DOUBLE_LIGHT, the output should look like this:
at.setTheme(V1_StandardTableThemes.DOUBLE_LIGHT);
at.render();
System.out.println(at.render());
The output will now be:
╓───────────────────────────────────────────────╖
║ Table Heading ║
╟──────────╥───────────────╥────────────────────╢
║row 1 ║this is col 2 ║and this is column 3║
╟──────────╫───────────────╫────────────────────╢
║row 2 ║some text for ║and some text for ║
║ ║column 2 ║column 3 ║
╙──────────╨───────────────╨────────────────────╜
The look and feel of themes with heavy characters can differ, depending on the font that is being used.
Many console fonts on windows do not show heavy box drawing characters as monotype or have varying width for whitespaces when using heavy character.
The following shows a table using the standard heavy theme (V1_StandardTableThemes.HEAVY):
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Table Heading ┃
┣━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┫
┃row 1 ┃this is col 2 ┃and this is column 3┃
┣━━━━━━━━━━╋━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━┫
┃row 2 ┃some text for ┃and some text for ┃
┃ ┃column 2 ┃column 3 ┃
┗━━━━━━━━━━┻━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━┛
There are also a number of LaTeX style themes pre-defined.
For instance V1_StandardTableThemes.LATEX_LIGHT_TRIPLE_DASH, which unfortunately does not render easily to HTML:
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
Table Heading
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
row 1 this is col 2 and this is column 3
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
row 2 some text for and some text for
column 2 column 3
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
Copyright © 2010–2015. All rights reserved.