Me neither too. It's on a "nice-to-have-but-not-required list", but the reqs specify that too much work is not rated better, but you do risk minus points for a not so good implementation. Anyway there are no real world customers for this small application and I think that's a good case
Anyway there are lots of places where you can find algorithms for the table sorting! To say to copy or not to copy: I also read Monkhouse's book and I have copied quite a few things from it, enhanced it, took stuff away. But then, if you look at other examples on the internet or Sun's own learnng material or books, you 'll find that in the end lots of it is just about the same. Only in Monkhouse's book it's more 'together packed' How could it be too different, it's all Java classes / functions ?
[ October 25, 2006: Message edited by: josine wilms ] [ October 25, 2006: Message edited by: josine wilms ]
SCJP 1.4<br />SCWCD 1.4<br />SCJD <br />SCEA (new version) Work in progress...
Sorting is good to have and not difficult to implement. So why not install it in your UI?
In your table model, you should have an array or list for the data, say,
which is visually displayed in JTable.
To implement sorting: First, you need to have a method (in your table model class) that sorts your data list (see dataList above). For example,
Second, this method will be called when you click on a table column header so add MouseListener to table header. The mouseClicked method of the listener will call the sort method. Note you should convert table's column index to the model's (using JTable's convertColumnIndexToModel method) when calling the sort method.
Joined: May 18, 2006
The problem is not in implementing sorting. I have done it in my table model. I have just thought of improving my design and implementing sorting as separate class. And such a class is already written, so why should I reinvent the wheel.
But as you all said it's "nice to have/not required" feature and I don't want take the risk, so I'll stay with sorting in table model.
For me the problem is: When I want to implement TableSorter - through some design patterns you end with something very similar to TableSorter from tutorial. Ad thus it is hard to say if it is your work (but _it_is_ my work)...
I'm very close to submitting. In my UI, I tried to follow the Java Look and Feel guidelines as closely as possible. JL&F is neutral on row sorting, so I probably did some extra work. I think I'll live dangerously and submit with a modification of the tutorial's table sorter. In a few weeks, I'll update this thread with notification of success or failure.
The tutorial's sorter did have some bugs in it. So, I did make some changes. I think it's appropriate to include Sun's copyright. If this was real code, would I need a second copyright to cover my fixes?