Hide a column in JTable?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Hide a column in JTable?

Hybrid View

  1. #1
    Lim Wing Hoe Guest

    Hide a column in JTable?

    How do I hide a particular column? I would still like to maintain all the
    data for that column there, so that I can retrieve the selected data easily,
    but I would like to have some columns that are not relevant to the user to
    be hidden.

    --



    Best Regards,
    Wing Hoe
    ---------------------------------------------------------------
    ICQ: 2213281
    Email: winghoe@hotmail.com
    www: http://pwp.maxis.net.my/winghoe
    Job Seeking Status : Active
    Availability : May 2001 (after degree course finish)
    ---------------------------------------------------------------





  2. #2
    Paul Clapham Guest

    Re: Hide a column in JTable?

    Set its width to zero. Or if you are never going to display it, don't even
    include it in your table. Just have your table model provide only the
    displayable data.

    PC2

    Lim Wing Hoe <winghoe@hotmail.com> wrote in message
    news:3a359ef6@news.devx.com...
    > How do I hide a particular column? I would still like to maintain all the
    > data for that column there, so that I can retrieve the selected data

    easily,
    > but I would like to have some columns that are not relevant to the user to
    > be hidden.
    >





  3. #3
    Ramkumar Guest

    Re: Hide a column in JTable?


    There are two or three methods of doing it.
    1.Use removeColumnModel on the JTable. This wont remove the actual data from
    the underlying tablemodel but only form the View the JTable. DIsadvantege
    of this is that if you want to restore the column it becomes messy coding.

    2.You can have an array of booleans saying whether each column is to be displayed
    or not. Then you should override the getValueAt and setValueAt,etc functions
    of the tablemodel so that the correct column number is used - for the column
    number passed by the JTable will be with respect to the columns displayed
    while the tablemodel's data Vector(or array) will be having more values.
    Search in codeguru.com for a full sample of this.

    I personally feel that method two is better.

    "Paul Clapham" <pclapham@core-mark.com> wrote:
    >Set its width to zero. Or if you are never going to display it, don't even
    >include it in your table. Just have your table model provide only the
    >displayable data.
    >
    >PC2
    >
    >Lim Wing Hoe <winghoe@hotmail.com> wrote in message
    >news:3a359ef6@news.devx.com...
    >> How do I hide a particular column? I would still like to maintain all

    the
    >> data for that column there, so that I can retrieve the selected data

    >easily,
    >> but I would like to have some columns that are not relevant to the user

    to
    >> be hidden.
    >>

    >
    >
    >



  4. #4
    Lim Wing Hoe Guest

    Re: Hide a column in JTable?

    Ramkumar,
    Thanks for replying. I've been analyzing the same theory that you mentioned,
    method 2. I will try to do this.
    Oh yeah, I've just sent a reply to the message "How to listen to JTable
    events?". I've written a piece of code near the end of the message in
    regards to how I'm gonna retrieve the data. Do you think it will work?

    --



    Best Regards,
    Wing Hoe
    ---------------------------------------------------------------
    ICQ: 2213281
    Email: winghoe@hotmail.com
    www: http://pwp.maxis.net.my/winghoe
    Job Seeking Status : Active
    Availability : May 2001 (after degree course finish)
    ---------------------------------------------------------------


    "Ramkumar" <ramkuma@usa.net> wrote in message
    news:3a3b2f95$1@news.devx.com...
    >
    > There are two or three methods of doing it.
    > 1.Use removeColumnModel on the JTable. This wont remove the actual data

    from
    > the underlying tablemodel but only form the View the JTable. DIsadvantege
    > of this is that if you want to restore the column it becomes messy coding.
    >
    > 2.You can have an array of booleans saying whether each column is to be

    displayed
    > or not. Then you should override the getValueAt and setValueAt,etc

    functions
    > of the tablemodel so that the correct column number is used - for the

    column
    > number passed by the JTable will be with respect to the columns displayed
    > while the tablemodel's data Vector(or array) will be having more values.
    > Search in codeguru.com for a full sample of this.
    >
    > I personally feel that method two is better.





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center