" Creating a sorted JList component " says
Java platform version 6, the standard version (Java SE, formerly called J2SE) will add sorting and filtering capabilities to javax.swing.JTable
. * Java Foundation / Swing classes (JFC / Swing) added the TableRowSorter
class to Java SE 6 to handle sorting and filtering. This class behaves like a decorator in that it represents the base model of the table and adds it by sorting it at runtime. You create a TableRowSorter
object TableRowSorter
providing the original table model in the constructor. Then you call the setRowSorter
table setRowSorter
. After that, the JTable
will use the TableRowSorter
to get the sorted view of the base model. Unfortunately, the same function is not yet available for the JList
class, and it will not be available in the next version. But we can borrow the decorator’s idea to create a SortedListModel
class that adds sorting capabilities to any ListModel
. Note. The demo application and code in this article apply to all versions of the JDK through version 6.
Has anyone heard if they plan to include it in Java 7, 8 or 9? Because that’s how I feel:
Lists are suitable user interface components for many applications, but an unsorted list has limited usefulness .
(highlighted by me)
source share