Topic: 请教JTable如何排序? |
Print this page |
1.请教JTable如何排序? | Copy to clipboard |
Posted by: Pan Posted on: 2005-07-28 09:20 我现在做了一个JTable,继承了一个AbstractTableModel,显示、查询等都正常,请教各位,不知如何能最简洁地实现单击列标题,升序或降序排列表格中的数据(Java Tutorial 上的TableSorter有些过于复杂),并加上行号(Row Header)?谢谢! |
2.Re:请教JTable如何排序? [Re: Pan] | Copy to clipboard |
Posted by: Pan Posted on: 2005-07-28 20:09 为什么没有回复呢? |
3.Re:请教JTable如何排序? [Re: Pan] | Copy to clipboard |
Posted by: Reeves1016 Posted on: 2005-07-29 21:02 基本思想是做一个map,key是序号,比如说某一列的第几个元素;value是真实的元素的。也就是说这个得自己实现,没有现成得方法 |
4.Re:请教JTable如何排序? [Re: Pan] | Copy to clipboard |
Posted by: Pan Posted on: 2005-07-30 09:04 谢谢Reeves1016!我按您说的试了一下,用Collections的sort方法对该map排序,只调整了某列的顺序,其他列的顺序未变化,怎样才能让所有行根据某列数据的顺序进行调整呢?谢谢! |
5.Re:请教JTable如何排序? [Re: Pan] | Copy to clipboard |
Posted by: bluepure Posted on: 2005-07-30 16:52 TableSorter 的例子复杂??? 几乎是拿来就用啊,非常简单的了。 http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#sorting http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableSorterDemo.java http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableMap.java http://java.sun.com/docs/books/tutorial/uiswing/components/example-1dot4/TableSorter.java |
6.Re:请教JTable如何排序? [Re: Pan] | Copy to clipboard |
Posted by: Pan Posted on: 2005-07-30 19:44 谢谢bluepure!我可能没有表达清楚,我想在我自己写的JTable中,用最简单的方法自己写相关代码实现Java Tutorial 上的TableSorter功能,而不是用他的代码,像 TableSorter sorter = new TableSorter(new MyTableModel())这样地实现。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |