[英]java JTable sort objects
I am sorry for asking this. 很抱歉问这个。 But I am having huge problems understanding how to do so.
但是我在理解如何做时遇到了巨大的问题。
I have a JTable
. 我有一个
JTable
。 For that JTable
I have my own AbstractTableModel
that returns a custom object for getValueAt
. 对于该
JTable
我有自己的AbstractTableModel
,它为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
. 另外,我还有一个自己的
TableCellRenderer
,它使用很多颜色,并使用列值从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
? 我还应该在创建
JTable
的类中,在AbstractTableModel
或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.
我很抱歉,但我确实为这种情况感到难过,而且从未做到过。
您可以使用Swing教程中所述的排序对象: http : //docs.oracle.com/javase/tutorial/uiswing/components/table.html#sorting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.