Jeff <> wrote:
> The best solution I can think of is to extend Vector to implement the
> Comparable interface, creating a class called ComparableVector for each row.
> In ComparableVector's compareTo() method, I'll compare the float value of
> each row. Then I can use the Arrays.sort() method to perform the sort. A
> Vector of ComparableVectors will provide the 2nd dimension.
>
> Does someone see a better solution?
Yes. You're entirely missing the concept of abstraction. You should
really have something like this:
public class MyDataRecord implements Comparable<MyDataRecord>
{
private String name;
private float value;
private int i1, i2;
...
public int compareTo(MyDataRecord other)
{
return Float.compare(value, other.value);
}
}
That use a Vector of those. You mentioned that the display of this data
in a Swing table is in another program, and there's nothing wrong with
using different data models for the same data in different programs.
However, if you would like to use a JTable to display the data in this
form, just define a subclass of AbstractTableModel to define a mapping
from a Vector<MyDataRecord> to the TableModel interface. You'll define
what field goes into what column by your implementation of getValueAt
(and probably getColumnName and getColumnClass as well).
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation