java JTable sort objects

一曲冷凌霜 提交于 2019-12-02 09:48:14

问题


I am sorry for asking this. But I am having huge problems understanding how to do so.

I have a JTable. For that JTable I have my own AbstractTableModel that returns a custom object for getValueAt. Additionally I also have my own TableCellRenderer that uses a lot of colors, and uses column value to extract specified values from object that is given by getValueAt.

However I would like to be able to sort values. So how would I go about sorting? I would like to be able to receive the two objects, and the column, and sort based on that.

I tried reading bunch of tutorials but they show how to sort either based on string, or just sort without knowing the column.

Also should I be doing sorting in the class where I create the JTable, or in AbstractTableModel or in TableCellRenderer?

Any help or pointing to good tutorial will be greatly appreciated. I am sorry but I really suck at this worsting and have never done it.

来源:https://stackoverflow.com/questions/20954334/java-jtable-sort-objects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!