Text Alignment: Table

The alignment of text can be set for the whole table at once, after all text objects are added.

The following code creates a table, adds text objects, and then sets the text alignment for the whole table to right.

Note: settings for the whole table only effect cells that have been already added.

1
2
3
4
5
6
7
8
9
AsciiTable at = new AsciiTable();
String text = new LoremIpsum().getWords(9);
at.addRule();
at.addRow(text, text, text);
at.addRule();
at.addRow(text, text, text);
at.addRule();
at.setTextAlignment(TextAlignment.RIGHT);
System.out.println(at.render(76));

The resulting output:

┌────────────────────────┬────────────────────────┬────────────────────────┐
│   Lorem ipsum dolor sit│   Lorem ipsum dolor sit│   Lorem ipsum dolor sit│
│        amet, consetetur│        amet, consetetur│        amet, consetetur│
│   sadipscing elitr, sed│   sadipscing elitr, sed│   sadipscing elitr, sed│
├────────────────────────┼────────────────────────┼────────────────────────┤
│   Lorem ipsum dolor sit│   Lorem ipsum dolor sit│   Lorem ipsum dolor sit│
│        amet, consetetur│        amet, consetetur│        amet, consetetur│
│   sadipscing elitr, sed│   sadipscing elitr, sed│   sadipscing elitr, sed│
└────────────────────────┴────────────────────────┴────────────────────────┘