设置垂直对齐

显示效果:

示例代码所生成的OFD文件:下载

 示例代码

package test.create.c04;

import iofd.layout.OfdDocument;
import iofd.layout.block.Paragraph;
import iofd.layout.block.Table;
import iofd.layout.contants.VerticalAlignmentType;
import iofd.layout.element.table.Cell;
import iofd.layout.element.table.HeadCell;
import iofd.layout.element.table.TableRow;

import java.util.ArrayList;
import java.util.List;

import test.create.TestDocUtil;

public class C0412TableSetColumnVerticalAlign {

	public static void main(String[] args) throws Throwable {
		C0412TableSetColumnVerticalAlign o = new C0412TableSetColumnVerticalAlign();
		o.done();
	}

	private void done() throws Throwable {
		String clzName = this.getClass().getSimpleName();
		System.out.println(clzName + " begin");

		OfdDocument doc = new OfdDocument();

		String s = "这是一个表格的示例,这里演示如何设置垂直对齐方式。";
		Paragraph p = new Paragraph();
		p.add(s);
		doc.add(p);

		TableRow row0 = new TableRow(0);
		List head0 = new ArrayList<>();
		HeadCell c = new HeadCell(0, 0, 0, 0);
		c.add("标题一【靠上对齐】");
		head0.add(c);
		c = new HeadCell(0, 1, 0, 0);
		c.add("标题二【垂直居中对齐】");
		head0.add(c);

		c = new HeadCell(0, 2, 0, 0);
		c.add("标题三【靠下对齐】");
		head0.add(c);

		row0.setCellList(head0);

		List head = new ArrayList<>();
		head.add(row0);

		List body = createBody();

		Table table = Table.createTable(head, body);
		doc.add(table);

		String fileName = TestDocUtil.getOfdFilePath(this.getClass());
		doc.save(fileName);
		System.out.println(clzName + " end");
	}

	private List createBody() throws Exception {
		List ret = new ArrayList<>();

		for (int i = 0; i < 10; i++) {
			TableRow row = new TableRow(i);
			List cellList = new ArrayList<>();
			for(int j = 0; j < 3; j++) {
				Cell c = new Cell(i, j);
				c.add("[" + i + "," + j + "]");
				c.setMinHeight(30f);
				if(j == 0) {
					/*
					 * 设置为顶部垂直对齐
					 * */
					c.setVertialAlign(VerticalAlignmentType.TOP);
				} else if(j == 1) {
					/*
					 * 设置为居中垂直对齐
					 * */
					c.setVertialAlign(VerticalAlignmentType.CENTER);
				} else {
					/*
					 * 设置为底部垂直对齐
					 * */
					c.setVertialAlign(VerticalAlignmentType.BUTTOM);
				}
				cellList.add(c);
			}
			row.setCellList(cellList);
			ret.add(row);
		}
		
		return ret;
	}
}