How to display and hide columns in jtable (custom public class)

Source: Internet
Author: User

/*
* 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 control public control class
* @ Author http://www.my400800.cn

*/
Public class jtablecomm {

/**
* Hide the specified column of the specified jtable
* @ Param table specify jtable
* @ Param column specify column
*/< BR> 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);
}

/**
* Display the specified column of the specified jtable
* @ Param table specifies the jtable
* @ Param column specifies the column
* @ Param width: Specifies the column display 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 );
}
}

Call method:

Hide the specified column of the specified jtable

Jtablecom. hiddencell (the jtable object of the column to be hidden, the column to be hidden starts from 0 );

Displays the specified columns of a specified jtable.

Jtablecom. hiddencell (the jtable object of the column to be displayed, the column to be displayed starts from 0, and the column width );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.