Results 1 to 9 of 9
  1. #1
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default table column sort

    I want to find out if a column is sorted Ascendingly using the following line, but it keeps giving me a Null Pointer exception. Does anyone know why? Or if you know of another way to find out how a tabal column is sorted?
    Thanks.

    if (Table.getRowSorter().getSortKeys().get(0).getSort Order().equals(SortOrder.ASCENDING))

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    10

    Default

    probably because one of the objects is null.

    - maybe table doesn't have a row sorter
    - maybe row sorter doesn't have keys
    - maybe the first key doesn't have sort order

    split your one line into separate assignments and you'll at least know what exactly is failing...

  3. #3
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    When a JTable is created it doesn't create a row sorter automaticall?

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    10

    Default

    good question. if you split up your line like I'm suggesting, you'll find the answer to that.

  5. #5
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    You are obsolutely correct. The row sorter is null.
    So now my question is, if this table doesn't have a road sorter, can I still be able to find out how the column is sorted?

  6. #6
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    10

    Default

    taking a look at How to Use Tables (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components), i think all you have to do is say

    Java Code:
    table.setAutoCreateRowSorter(true);
    which indeed seem kind of crooked... hope that works.

  7. #7
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    The table I am dealing with is an existing table which I don't want to make any changes if I don't have to.
    Without a rowsorter, can I still be able to find out how the columns are sorted?

  8. #8
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    10

    Default

    i doubt it, frankly...

  9. #9
    new2java2009 is offline Member
    Join Date
    Aug 2009
    Posts
    60
    Rep Power
    0

    Default

    If I am going to add a row sorter...

    The following table model "DtableModel"extends "AbstractTableModel" (old code)

    DTableModel model = new DTableModel(columnDefinitions);

    I added the following:

    final TableRowSorter<DTableModel> sorter = new TableRowSorter<DTableModel>(model);

    this.indicationTable.setRowSorter(sorter);

    The statement "this.indicationTable.setRowSorter(sorter);" gave me an exception.

    Do I have to use DefaultTableModel instead of my own (DTableModel)?

Similar Threads

  1. Filter table model by data in specific column
    By ribbs2521 in forum New To Java
    Replies: 9
    Last Post: 10-29-2009, 04:41 AM
  2. Non-Editable Table Column
    By ld_pvl in forum AWT / Swing
    Replies: 6
    Last Post: 08-03-2009, 06:35 PM
  3. How to insert a SWT table column at an index
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:30 PM
  4. Sorting a SWT table by column
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 03:07 PM
  5. How to sort column in JTable
    By johnt in forum AWT / Swing
    Replies: 3
    Last Post: 06-14-2008, 05:48 AM

Posting Permissions

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