zoukankan      html  css  js  c++  java
  • JTable显示和隐藏列的方法(自定义公用类)

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package comm.SwingComm;

    import javax.swing.JTable;
    import javax.swing.table.TableColumn;

    /**
     *JTable 控件公共操纵类
     * @author http://www.my400800.cn
     */
    public class JTableComm {

        /**
         * 隐藏指定JTable的指定列
         * @param table    指定JTable
         * @param column   指定列
         */
        public static void HiddenCell(JTable table, int column) {
            TableColumn tc = table.getTableHeader().getColumnModel().getColumn(column);
            tc.setMaxWidth(0);
            tc.setPreferredWidth(0);
            tc.setWidth(0);
            tc.setMinWidth(0);
            table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(0);
            table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(0);
        }

        /**
         * 显示指定JTable的指定列
         * @param table    指定JTable
         * @param column   指定列
         * @param width    指定列显示宽度
         */
        public static void showColumn(JTable table, int column, int width) {
            TableColumn tc = table.getColumnModel().getColumn(column);
            tc.setMaxWidth(width);
            tc.setPreferredWidth(width);
            tc.setWidth(width);
            tc.setMinWidth(width);
            table.getTableHeader().getColumnModel().getColumn(column).setMaxWidth(width);
            table.getTableHeader().getColumnModel().getColumn(column).setMinWidth(width);
        }
    }

    调用方法:

    隐藏指定JTable的指定列

    JTableCom. HiddenCell(要隐藏列的JTable对象, 要隐藏的列从0开始);

    显示指定JTable的指定列

    JTableCom. HiddenCell(要显示列的JTable对象, 要显示的列从0开始,列宽);

  • 相关阅读:
    用C++读写EXCEL文件的几种方式比较
    20个值得收藏的网页设计开放课件
    char* 应用, 去除字符串内多余空格, 用算法而非库函数
    东拉西扯:王建硕主义
    Lisp 的本质(The Nature of Lisp)
    web前端:html
    [原译]理解并实现原型模式实现ICloneable接口.理解深浅拷贝
    [原译]理解并实现装饰器模式
    3分钟理解Lambda表达式
    [原译]实现IEnumerable接口&理解yield关键字
  • 原文地址:https://www.cnblogs.com/jishu/p/1940038.html
Copyright © 2011-2022 走看看