CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: JTable

  1. #1
    Join Date
    Mar 2000
    Posts
    12

    JTable

    Hi,everyone:
    I want to design a table in Java, this table has 3 fixed columns,more than 20 non-fixed columns, and I want to support sorting by column. I searched the Internet, and found somebody designed a table which suppots sorting but doesn't support fixed columns, and somebody designed a table which supports fixed columns but does not support sorting. I am wondering if somebody can give me an idea how to design a table which supports sorting by column and supports fixed columns?

    Thanks in advance!

    Rose Zhou


  2. #2
    Join Date
    Nov 1999
    Location
    Indianapolis, IN
    Posts
    191

    Re: JTable

    If you are just wanting to prevent the user from moving columns:
    this.getSavedTransfersTable().getTableHeader().setReorderingAllowed(false);

    For sorting, see http://www.hmravens.com/index.html?h...e/source.shtml

    and
    http://java.sun.com/docs/books/tutor...e.html#sorting


  3. #3
    Join Date
    Mar 2000
    Posts
    12

    Re: JTable

    Hi, mjpell:

    Thank you very much for your response!
    I don't want to prevent the user from moving all the columns, instead I only want to set some of the columns fixed, and others are non-fixed.There is an example here:
    http://codeguru.developer.com/java/articles/128.shtml
    Actually in this example, the author used two tables. If I sort one of the two tables, I must adjust another table in the same order. I don't know how to do this. Any idea?

    Thanks in advance!


  4. #4
    Join Date
    Nov 1999
    Location
    Indianapolis, IN
    Posts
    191

    Re: JTable

    I don't have any great ideas. You might poke around the JTable code and try to figure out how it implements making all columns fixed (see prev post). Maybe you can subclass JTable and reimplement this behavior?

    Maybe you can disable being able to select individual columns? and this would prevent user from being able to move it?

    If you want to try the 2 tables idea, try using the same instance of a tableModel for both tables. When the table gets sorted, sort the data in the tableModel, then call fireDataChanged() (or something similar) to repaint the tables.

    At least this is where I'd start looking. Or I might re-look at my requirements. :-)

    Good luck,


  5. #5
    Join Date
    Mar 2000
    Posts
    12

    Re: JTable

    Hi,mjpell:

    Thank you very much!
    I sorted the problem. I used the two tables idea. When one of the table is sorted, I get indexes of this table, and pass the indexes to another table to force another table to sort in the same order, and fireTableDataChanged event. It works.
    I have another problem. I want to make some of the column names into two lines, for example the column name is 12:15-12:30, I want to put 12:15- in one line, and put 12:30 in another line, this will make the column thinner. Any idea?

    Thanks!


  6. #6
    Join Date
    Nov 1999
    Location
    Indianapolis, IN
    Posts
    191

    Re: JTable

    Try putting a "\r" or "\r\n" or "\n" in your column name. So your column name would be "12:15 -\r12:30"

    I've not tried this, but it seems as though it should work.
    Please let me know if it does.


  7. #7
    Join Date
    Mar 2000
    Posts
    12

    Re: JTable

    Hi,mjpell:

    Thank you very much!

    Putting a "\r" or "\r\n" in the column name can not force the column into two lines.

    I found an very good example here:
    http://codeguru.developer.com/java/articles/126.shtml

    Cheers!




Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured