Grids: Grid Themes

Grids support different themes. A grid theme defines which grid characters from which position should be rendered. All other character will be rendered using a default character, usually blank.

The following example creates a table and then renders it using different grid themes:

  • full grid

  • no grid

  • corners only (top left, top right, bottom left, bottom right)

  • corners and connectors (all 4 corners and every grid element that connects multiple grid lines)

  • horizontal lines only (no corners, no connectors)

  • vertical lines only (no corners, no connectors)

  • inside grid elements (lines and connectors)

  • outside grid elements (lines and connectors and corners)

  • left lines only

  • top and bottom lines only

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("rc 11", "rc 12");
at.addRule();
at.addRow("rc 21", "rc 22");
at.addRule();
at.getContext().setWidth(13);

System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.NONE);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.CORNERS);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.CC);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.HORIZONTAL);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.VERTICAL);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.INSIDE);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.OUTSIDE);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.LEFT);
System.out.println(at.render());

at.getContext().setGridTheme(TA_GridThemes.TOPBOTTOM);
System.out.println(at.render());

The resulting output (5 examples next to each other):

┌─────┬─────┐                         ┌           ┐      ┌     ┬     ┐       ───────────
│rc 11│rc 12│       rc 11 rc 12        rc 11 rc 12        rc 11 rc 12        rc 11 rc 12
├─────┼─────┤                                            ├     ┼     ┤       ───────────
│rc 21│rc 22│       rc 21 rc 22        rc 21 rc 22        rc 21 rc 22        rc 21 rc 22
└─────┴─────┘                         └           ┘      └     ┴     ┘       ───────────

                                      ┌───────────┐                          ───────────
│rc 11│rc 12│       rc 11│rc 12       │rc 11 rc 12│      │rc 11 rc 12        rc 11 rc 12
│     │     │       ─────┼─────       │           │      │
│rc 21│rc 22│       rc 21│rc 22       │rc 21 rc 22│      │rc 21 rc 22        rc 21 rc 22
                                      └───────────┘                          ───────────