zoukankan      html  css  js  c++  java
  • JTable调整列宽 规格严格

    1。//   取得列幅的最大值
        private   int   getPreferredWidthForCloumn(JTable   table,int   icol){

            TableColumnModel   tcl   =   table.getColumnModel();
            TableColumn   col   =   tcl.getColumn(icol);
            int   c   =   col.getModelIndex(),width   =   0,maxw   =   0;

            for(int   r=0;r <table.getRowCount();++r){

                TableCellRenderer   renderer   =   table.getCellRenderer(r,c);
                Component   comp   =   renderer.getTableCellRendererComponent(table,table.getValueAt(r,c),false,false,r,c);
                width   =   comp.getPreferredSize().width;
                maxw   =   width   >   maxw?maxw;
            }

    2。自动设定列的宽度

            // 设定每列的宽度为当列的最大的宽度。
            for(int   i=   0;   i <table.getColumnCount();   i++){
                int   with   =   this.getPreferredWidthForCloumn(table,i)   +   10;
                with   =   iniCW[i]   >   with   ?   iniCW[i]   :   with;
                table.getColumnModel().getColumn(i).setPreferredWidth(with);
            }
  • 相关阅读:
    jQuery工具函数
    jQuery中的Ajax
    jQuery动画效果
    jQuery基础事件
    jQuery操作DOM和CSS函数
    jQuery基础DOM和CSS操作
    jQuery过滤选择器
    jQuery常规选择器
    -3dB的理解
    诺顿定理概述
  • 原文地址:https://www.cnblogs.com/diyunpeng/p/2304932.html
Copyright © 2011-2022 走看看