Setting paragraph width

The width of a paragraph can be set via its context. The following example creates a paragraph and then sets the width and shows the output. The first width is 50 (line 5), the second 40 (line 8), and the third 30 characters (line 11).

1
2
3
4
5
6
7
8
9
10
11
12
AsciiParagraph ap = new AsciiParagraph();
ap.addText(new LoremIpsum().getWords(20));
ap.getContext().setAlignment(TextAlignment.LEFT);

ap.getContext().setWidth(50);
System.out.println(ap.render());

ap.getContext().setWidth(40);
System.out.println(ap.render());

ap.getContext().setWidth(30);
System.out.println(ap.render());

The first output is for a width of 50:

Lorem ipsum dolor sit amet, consetetur sadipscing
elitr, sed diam nonumy eirmod tempor invidunt ut
labore et dolore magna aliquyam

The second output is for a width of 40:

Lorem ipsum dolor sit amet, consetetur
sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore
magna aliquyam

The third output is for a width of 30:

Lorem ipsum dolor sit amet,
consetetur sadipscing elitr,
sed diam nonumy eirmod tempor
invidunt ut labore et dolore
magna aliquyam