views:

49

answers:

3

I have a table where the first column contains Strings and the second contains doubles.

    stars = new StarDatabase(path);
    Object[][] data = new Object[stars.size()][2];
    int i = 0;
    for (String name : stars.keySet()) {
        data[i][0] = name;
        data[i++][1] = stars.get(name).period;
    }
    StarsTable = new JTable(data, StarsColumnNames);
    StarsTable.setAutoCreateRowSorter(true);

The doubles are sorted as strings, so 1 < 15 < 2 < 25 < 3. How can I fix this?

+1  A: 

A few very good hints here!

Carl Smotricz
+1  A: 

The key to this is found in How to Use Tables—Concepts: Editors and Renderers. Just make sure your second column actually contains Double values. Either of the available valueOf() methods may be used to make the type explicit.

trashgod
+1  A: 

Try using GlazedList .. it just invloves few line of code and very neat .Glazedlist


harshit