Question: How do you hide columns and rows in a JTable component?http://developer.java.sun.com/developer/qow/archive/10/

解决方案 »

  1.   

    我这么用,很不错!
      /**
       * 隐藏表的指定列,该方法只是将指定列的列宽设定为0,不影响取隐藏列的value和排序等操作
       * @param columnIndex
       */
      private void hiddenColumn ( int columnIndex )
      {
        TableColumnModel tcm = table.getColumnModel();
        TableColumn tc = tcm.getColumn( columnIndex );
        //tc.setResizable(false);
        tc.setWidth( 0 );
        tc.setPreferredWidth( 0 );
        tc.setMaxWidth( 0 );
        tc.setMinWidth( 0 );
        table.getTableHeader().getColumnModel().getColumn( columnIndex ).
    setMaxWidth(
    0 );
        table.getTableHeader().getColumnModel().getColumn( columnIndex ).
    setMinWidth(
    0 );
      }