• jtable列表自适应大小


    转载:http://blog.chinaunix.net/uid-20771867-id-83272.html

    • public void FitTableColumns(JTable myTable) {   
    •          JTableHeader header = myTable.getTableHeader();   
    •         int rowCount = myTable.getRowCount();   
    •   
    •          Enumeration columns = myTable.getColumnModel().getColumns();   
    •         while (columns.hasMoreElements()) {   
    •              TableColumn column = (TableColumn) columns.nextElement();   
    •             int col = header.getColumnModel().getColumnIndex(column.getIdentifier());   
    •             int width = (int) myTable.getTableHeader().getDefaultRenderer()   
    •                      .getTableCellRendererComponent(myTable, column.getIdentifier(), false, false,   
    •                              -1, col).getPreferredSize().getWidth();   
    •             for (int row = 0; row < rowCount; row++) {   
    •                 int preferedWidth = (int) myTable.getCellRenderer(row, col)   
    •                          .getTableCellRendererComponent(myTable, myTable.getValueAt(row, col),   
    •                                 false, false, row, col).getPreferredSize().getWidth();   
    •                  width = Math.max(width, preferedWidth);   
    •              }   
    •              header.setResizingColumn(column); // 此行很重要   
    •              column.setWidth(width + myTable.getIntercellSpacing().width);   
    •          }   
    •      } 
  • 相关阅读:
    可怕的沉默
    我排着队 拿着号码牌
    移动改名正在运行的程序
    C# 注册热键
    c#通过编码检查是否有PendingChanges没有签入
    c#读取带命名空间的xml
    自动查找并关闭窗口
    C# 应用微软的Visual Studio International Pack 类库提取汉字拼音首字母
    C#执行DOS命令(CMD命令) (转)
    asp.net 文件下载,有进度条
  • 原文地址:https://www.cnblogs.com/gwq369/p/5364708.html
Copyright © 2020-2023  润新知