简体   繁体   English

java JTable排序对象

[英]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的类中,在AbstractTableModelTableCellRenderer进行排序吗?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM