Tuesday 13 July 2021

AsciiTable: Add padding characters to the text

Padding can be added to text in cells above (top) and below (bottom) the text or in front (left) or behind (right) each line.

 

Following methods are used to add padding characters for all the cells in a table.

public AsciiTable setPaddingLeftChar(Character paddingLeftChar) 
public AsciiTable setPaddingRightChar(Character paddingRightChar) 
public AsciiTable setPaddingTopChar(Character paddingTopChar)
public AsciiTable setPaddingBottomChar(Character paddingBottomChar)

 

Example

asciiTable.setPaddingLeftChar('>');
asciiTable.setPaddingRightChar('=');
asciiTable.setPaddingTopChar('^');
asciiTable.setPaddingBottomChar('<');

 

Find the below working application.

 

SetPaddingDemo.java

package com.sample.app;

import de.vandermeer.asciitable.AsciiTable;
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment;

public class SetPaddingDemo {

	public static void main(String args[]) {

		AsciiTable asciiTable = new AsciiTable();

		asciiTable.addRule();
		asciiTable.addRow("Row 1 col 1", "Row 1 col 2");

		asciiTable.addRule();
		asciiTable.addRow("Row 2 col 1", "Row 2 col 2");

		asciiTable.addRule();
		asciiTable.addRow("Row 3 col 1", "Row 3 col 2");
		asciiTable.addRule();
		
		asciiTable.setTextAlignment(TextAlignment.CENTER);

		asciiTable.setPaddingLeftChar('>');
		asciiTable.setPaddingRightChar('=');
		asciiTable.setPaddingTopChar('^');
		asciiTable.setPaddingBottomChar('<');
		asciiTable.setPadding(1);

		String rend = asciiTable.render(35);
		System.out.println(rend);

	}

}

 

Output


 


Previous                                                    Next                                                    Home

No comments:

Post a Comment