zoukankan      html  css  js  c++  java
  • Java Console/控制台 打印表格

    功能:控制台打印表格,支持字段动态长度,左对齐,右对齐,居中,设置最大列长,设置列间隔符,设置最多打印多少行。

    类下载地址:http://download.csdn.net/download/j506825719/10211082

    简单使用方法:在new的时候,给定列名,和列值List,之后调用printTable就得到了表格字符串。

    进阶使用方法:查看所有public方法,就能知道还有什么功能了。

    效果图如下:


    接口如下:

    1. package com.benjamin.debug.extendclass;
    2. import java.awt.Font;
    3. import java.util.ArrayList;
    4. import java.util.HashMap;
    5. import java.util.List;
    6. import java.util.Map;
    7. /**
    8. *
    9. * @author Benjamin su
    10. * QQ:506825719
    11. * Email:jiang506825719@qq.com
    12. *
    13. */
    14. public class TextTable {
    15. //这个变量只是用来获取字符串的标准长度,修改无意义
    16. private static Font font = new Font("宋体", Font.PLAIN, 16);
    17. private String columnInterval="|";//列之间的间隔符号
    18. private AlignType at=AlignType.Left;
    19. private Integer MaxValueLenth=40;
    20. private Map<String,Integer> maxFieldValueLengthMap=null;
    21. List<String> columnNameList=null;
    22. List<List<String>> columnValueList=null;
    23. private boolean isException=false;
    24. private Integer pringtTableRow=30;
    25. /**
    26. * 初始化时不给定列长度Map
    27. * @param columnNameListTmp
    28. * @param columnValueListTmp
    29. */
    30. public TextTable(List<String> columnNameListTmp,List<List<String>> columnValueListTmp){
    31. }
    32. /**
    33. * 初始化时给定列长度Map
    34. * @param columnNameListTmp
    35. * @param columnValueListTmp
    36. * @param maxFieldValueLengthMapTmp
    37. */
    38. public TextTable(List<String> columnNameListTmp,List<List<String>> columnValueListTmp,Map<String,Integer> maxFieldValueLengthMapTmp){
    39. }
    40. /**
    41. * 获得处理后的表格字符串
    42. * @return
    43. */
    44. public String printTable(){
    45. }
    46. /**
    47. * 获取一个字符串的标准长度是多少
    48. * A2*. 这样是四个标准长度
    49. * 系统系统 这样是8个标准长度
    50. * @param str
    51. * @return
    52. */
    53. public static Integer getStrPixelsLenth(String str){
    54. }
    55. /**
    56. * 让列值居中
    57. * @param columnValue
    58. * @param ColumnPixelsLenth
    59. * @return
    60. */
    61. private String makeValueCenter(String columnValue,Integer repaireStrLength){
    62. }
    63. /**
    64. * 让列值左对齐
    65. * @param columnValue
    66. * @param ColumnPixelsLenth
    67. * @return
    68. */
    69. private String makeValueLeft(String columnValue,Integer repaireStrLength){
    70. }
    71. /**
    72. * 让列值右对齐
    73. * @param columnValue
    74. * @param ColumnPixelsLenth
    75. * @return
    76. */
    77. private String makeValueRight(String columnValue,Integer repaireStrLength){
    78. }
    79. /**
    80. * 获取用于填充的字符串
    81. * @param str
    82. * @param PixelsLenth
    83. * @return
    84. */
    85. private static String getRepairStr(char str,Integer PixelsLenth){
    86. }
    87. /**
    88. * 根据像素长度来切割字符串
    89. * @param str
    90. * @param PixelsLenth
    91. * @return
    92. */
    93. private static String subStrByPixels(String str,Integer PixelsLenth){
    94. }
    95. /**
    96. * 让列值对齐(左对齐OR居中OR右对齐)
    97. * @param columnValue
    98. * @param ColumnPixelsLenth
    99. * @return
    100. */
    101. private String makeValueAlign(String columnValue,Integer ColumnPixelsLenth){
    102. }
    103. /**
    104. * 设置列与列之间用什么间隔,默认是|
    105. * @param columnInterval
    106. */
    107. public void setColumnInterval(String columnInterval) {
    108. }
    109. /**
    110. * 设置列值最大长度,超过则用省略号代替
    111. * @param maxValueLenth
    112. */
    113. public void setMaxValueLenth(Integer maxValueLenth) {
    114. }
    115. /**
    116. * 如果不指定列长度Map,这里将自动计算
    117. * @param columnNameListTmp
    118. * @param columnValueListTmp
    119. * @param maxFieldValueLengthMapTmp
    120. */
    121. private void setMaxFieldValueLengthMap(List<String> columnNameListTmp,List<List<String>> columnValueListTmp,Map<String, Integer> maxFieldValueLengthMapTmp) {
    122. }
    123. /**
    124. * 设置最多打印多少行
    125. * @param pringtTableRow
    126. */
    127. public void setPringtTableRow(Integer pringtTableRow) {
    128. }
    129. /**
    130. * 设置对齐方式
    131. * @param at
    132. */
    133. public void setAt(AlignType at) {
    134. }
    135. public enum AlignType {
    136. Left,
    137. Center,
    138. Rigth
    139. }
    140. }



    原文地址:https://blog.csdn.net/j506825719/article/details/78996659
  • 相关阅读:
    华为 简单OSPF实验
    华为 基于MAC地址的VLAN划分
    完全背包
    01背包问题
    90. 子集 II
    Java去除字符串中的特殊符号或者指定的字符
    Java查找指定文件夹下的所有文件
    Java面试基础
    Spring获取ApplicationContext
    JSP & EL & JSTL
  • 原文地址:https://www.cnblogs.com/jpfss/p/11496440.html
Copyright © 2011-2022 走看看