Width: Longest Word (Minimum)

This width calculator takes the longest word in each column and sets the column width to it. It can be further configured to a minimum column width.

The following code shows a few examples for the behavior of this width calculator for a table with 2 columns:

  • First example: minimum width set to 9 for all columns

  • Second example: minimum width of first column removed, minimum width of second column set to 30

1
2
3
4
5
6
7
8
9
10
11
12
AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("first", "information");
at.addRule();
at.addRow("second", "info");
at.addRule();

at.getRenderer().setCWC(new CWC_LongestWordMin(9));
System.out.println(at.render());

at.getRenderer().setCWC(new CWC_LongestWordMin(new int[]{-1,30}));
System.out.println(at.render());

The resulting output for the first example:

┌─────────┬───────────┐
│first    │information│
├─────────┼───────────┤
│second   │info       │
└─────────┴───────────┘

The resulting output for the second example:

┌──────┬──────────────────────────────┐
│first │information                   │
├──────┼──────────────────────────────┤
│second│info                          │
└──────┴──────────────────────────────┘