Margins

The implementation allows to add margins before and after the table as well as left and right of each line (outside the grid). For each margin, the number and the character can be set. The number states the margin to be added (number of lines for top/bottom, number of characters for left/rigth).

The following code creates a table and then adds one line top margin, 2 line bottom margin, 3 characters left margin, and 4 characters right margin. Each setting uses a different margin character.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("row 1 col 1", "row 1 col 2");
at.addRule();
at.addRow("row 2 col 1", "row 2 col 2");
at.addRule();

at.getContext().setFrameTopChar('v');
at.getContext().setFrameBottomChar('^');
at.getContext().setFrameLeftChar('>');
at.getContext().setFrameRightChar('<');

at.getContext().setFrameTopMargin(1);
at.getContext().setFrameBottomMargin(2);
at.getContext().setFrameLeftMargin(3);
at.getContext().setFrameRightMargin(4);

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

The resulting output:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
>>>┌───────────┬───────────┐<<<<
>>>│row 1 col 1│row 1 col 2│<<<<
>>>├───────────┼───────────┤<<<<
>>>│row 2 col 1│row 2 col 2│<<<<
>>>└───────────┴───────────┘<<<<
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^