Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2009
    Posts
    23
    Rep Power
    0

    Default Sorting and hiding columns in JTable

    Hi,

    I have a Jtable i would like to sort by one particular columns (that is filled with ints). However I do not particularly want the user to see this column. I want them to press a button I have and have that be equivalent to them clicking on this columns header.


    in short: can i sort by a hidden column in Jtable and how?


    Thank you!!!!

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    I think you can hack together a way to do this however it won't be pretty. I could be completely wrong I'm going off pure memory of what's available with a JTable object.

    I believe there's a setVisible() method with rows and cols that you can turn off. Also say you have 4 cols and the 4th column has your values you don't want the user to see. You can sort by that column and then put all the values in order into an array and then redraw a new table with only 3 columns and input everything from the array.

    I'm assuming each row is an object and each col an attribute of that object so you should be able to resort and repopulate everything using getter methods.
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

Similar Threads

  1. Replies: 7
    Last Post: 09-23-2009, 08:28 PM
  2. Sorting JTable
    By mm2236 in forum AWT / Swing
    Replies: 0
    Last Post: 04-09-2009, 05:37 PM
  3. How to sort a JTable for multiple columns?
    By BLR in forum Advanced Java
    Replies: 2
    Last Post: 03-16-2009, 11:41 AM
  4. Right Align columns in JTable
    By Laura Warren in forum New To Java
    Replies: 2
    Last Post: 12-18-2008, 10:01 PM
  5. sort columns in jtable
    By Alan in forum AWT / Swing
    Replies: 2
    Last Post: 05-14-2007, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •