功能:控制台打印表格,支持字段動態長度,左對齊,右對齊,居中,設置最大列長,設置列間隔符,設置最多打印多少行。
類下載地址:http://download.csdn.net/download/j506825719/10211082
簡單使用方法:在new的時候,給定列名,和列值List,之后調用printTable就得到了表格字符串。
進階使用方法:查看所有public方法,就能知道還有什么功能了。
效果圖如下:
接口如下:
-
package com.benjamin.debug.extendclass;
-
-
import java.awt.Font;
-
import java.util.ArrayList;
-
import java.util.HashMap;
-
import java.util.
List;
-
import java.util.Map;
-
-
/**
-
*
-
* @author Benjamin su
-
* QQ:506825719
-
* Email:jiang506825719@qq.com
-
*
-
*/
-
public
class TextTable {
-
//這個變量只是用來獲取字符串的標准長度,修改無意義
-
private
static Font font =
new Font(
"宋體", Font.PLAIN,
16);
-
private String columnInterval=
"|";
//列之間的間隔符號
-
private AlignType at=AlignType.Left;
-
private Integer MaxValueLenth=
40;
-
private Map<String,Integer> maxFieldValueLengthMap=
null;
-
List<String> columnNameList=
null;
-
List<
List<String>> columnValueList=
null;
-
private boolean isException=
false;
-
private Integer pringtTableRow=
30;
-
/**
-
* 初始化時不給定列長度Map
-
* @param columnNameListTmp
-
* @param columnValueListTmp
-
*/
-
public TextTable(
List<String> columnNameListTmp,
List<
List<String>> columnValueListTmp){
-
}
-
/**
-
* 初始化時給定列長度Map
-
* @param columnNameListTmp
-
* @param columnValueListTmp
-
* @param maxFieldValueLengthMapTmp
-
*/
-
public TextTable(
List<String> columnNameListTmp,
List<
List<String>> columnValueListTmp,Map<String,Integer> maxFieldValueLengthMapTmp){
-
}
-
-
/**
-
* 獲得處理后的表格字符串
-
* @return
-
*/
-
public String printTable(){
-
}
-
/**
-
* 獲取一個字符串的標准長度是多少
-
* A2*. 這樣是四個標准長度
-
* 系統系統 這樣是8個標准長度
-
* @param str
-
* @return
-
*/
-
public
static Integer getStrPixelsLenth(String str){
-
}
-
/**
-
* 讓列值居中
-
* @param columnValue
-
* @param ColumnPixelsLenth
-
* @return
-
*/
-
private String makeValueCenter(String columnValue,Integer repaireStrLength){
-
}
-
/**
-
* 讓列值左對齊
-
* @param columnValue
-
* @param ColumnPixelsLenth
-
* @return
-
*/
-
private String makeValueLeft(String columnValue,Integer repaireStrLength){
-
}
-
/**
-
* 讓列值右對齊
-
* @param columnValue
-
* @param ColumnPixelsLenth
-
* @return
-
*/
-
private String makeValueRight(String columnValue,Integer repaireStrLength){
-
}
-
/**
-
* 獲取用於填充的字符串
-
* @param str
-
* @param PixelsLenth
-
* @return
-
*/
-
private
static String getRepairStr(char str,Integer PixelsLenth){
-
}
-
/**
-
* 根據像素長度來切割字符串
-
* @param str
-
* @param PixelsLenth
-
* @return
-
*/
-
private
static String subStrByPixels(String str,Integer PixelsLenth){
-
}
-
/**
-
* 讓列值對齊(左對齊OR居中OR右對齊)
-
* @param columnValue
-
* @param ColumnPixelsLenth
-
* @return
-
*/
-
private String makeValueAlign(String columnValue,Integer ColumnPixelsLenth){
-
}
-
/**
-
* 設置列與列之間用什么間隔,默認是|
-
* @param columnInterval
-
*/
-
public void setColumnInterval(String columnInterval) {
-
}
-
/**
-
* 設置列值最大長度,超過則用省略號代替
-
* @param maxValueLenth
-
*/
-
public void setMaxValueLenth(Integer maxValueLenth) {
-
}
-
/**
-
* 如果不指定列長度Map,這里將自動計算
-
* @param columnNameListTmp
-
* @param columnValueListTmp
-
* @param maxFieldValueLengthMapTmp
-
*/
-
private void setMaxFieldValueLengthMap(
List<String> columnNameListTmp,
List<
List<String>> columnValueListTmp,Map<String, Integer> maxFieldValueLengthMapTmp) {
-
}
-
/**
-
* 設置最多打印多少行
-
* @param pringtTableRow
-
*/
-
public void setPringtTableRow(Integer pringtTableRow) {
-
}
-
/**
-
* 設置對齊方式
-
* @param at
-
*/
-
public void setAt(AlignType at) {
-
}
-
public enum AlignType {
-
Left,
-
Center,
-
Rigth
-
}
-
}