“Creating a Sorted JList Component”说,
Version 6 of the Java Platform, Standard Edition (Java SE, formerly referred to as J2SE) will add sorting and filtering abilities to the
javax.swing.JTable
class.* The Java Foundation Classes/Swing (JFC/Swing) engineering team has added aTableRowSorter
class to Java SE 6 to handle sorting and filtering. This class behaves like a decorator in that it represents the underlying table model and adds sorting to it at runtime. You create aTableRowSorter
object by providing the original table model in the constructor. Then you call the table'ssetRowSorter
method. Thereafter, theJTable
object will use theTableRowSorter
object to get a sorted representation of the base model. Unfortunately, this same feature is not yet available for theJList
class, nor will it be available in the next release. But we can borrow the decorator idea to create aSortedListModel
class that adds sorting abilities to anyListModel
object. Note: The demo application and code in this article apply to all versions of the JDK through version 6.
有没有人听说他们计划将它包含在 Java 7、8 或 9 中?因为这就是它给我的感觉:
Lists are appropriate UI components for many applications, but an unsorted list has limited usefulness.
(我强调的)
最佳答案
无法说明原因 - 如果您需要可排序的 ListView ,请使用 JXList(属于 SwingX 项目):它支持按照与 J/X/Table 完全相同的方式进行排序/过滤。
关于java - 为什么 Sorted JLists 还没有成为标准 Swing 库的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8454931/