Text Alignment: Row

The alignment of text can be set for individual table rows.

The following code creates a table, adds text objects, and then sets the text alignment for the second row to right leaving the first row to the default justified alignment.

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_Row row = at.addRow(text, text, text);
at.addRule();
row.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│
└────────────────────────┴────────────────────────┴────────────────────────┘