0

Normally i get the Data from my Tablemodel

    table.setModel(new DefaultTableModel(
        new Object[][] {
            {"xxx", new Integer(10)},
            {"xx", new Integer(40)},
            {"x", new Integer(20)},
            {"xxxxxx", new Integer(50)},
            {"xxxxx", new Integer(30)},
        },
        new String[] {
            "name", "tel"
        }

But now i would get the Data from the "name" and "tel" from other Methods. The first method returns a String, who i would put in the "name". The second method returns a Integer, who i would put in the "tel". Then i would sort it, that the lowest integer is the first. Any name has his own telephonenumber.

My method Sorter:

public void sort()
{
     TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>();
        table.setRowSorter( sorter );
        sorter.setModel( model );   
}
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {}

But it doesn't sort, i don't know what i should do.

thelittlePanda
  • 101
  • 2
  • 10
  • 1
    Unrelated, but: Don't use Integers for telephone numbers! – tobias_k Jun 03 '15 at 12:40
  • I don't know how i get the (dynamic) data from a other method, And second problem is that i can't sort my data. sorter.setSortable(2, true); <- so i specify the column to sort, but that doesn't works, too :( – thelittlePanda Jun 03 '15 at 12:52
  • I think you will have to provide more code, then, particularly how you create/populate the table and how you (try to) sort it. – tobias_k Jun 03 '15 at 12:55
  • I don't understand your question. But you only have two columns, so if you want to sort the 2nd column you would use "1" as the index for the sorter. – camickr Jun 03 '15 at 14:45

1 Answers1

0

Check this you should get your answer

Sort Java Collection

Sorting is best when you hava made a collection. I preffer to make a collection than sort it and than display it on JTable.

https://docs.oracle.com/javase/tutorial/collections/algorithms/

Community
  • 1
  • 1
Programmer
  • 445
  • 4
  • 12